Redirect www to non-www

How to redirect www to non-www? e.g redirect to



If you use Apache as a web server, there are plenty of .htaccess
tricks to do just that. Google around a bit.


Here is a virtual host definition for apache that does the other way
around, I am sure it you could adjust it for what you want. Bear in
mind you will need mod_rewrite available on your server. If you do
not have your own server then you usually have to implement this in
the .htaccess file as explained by Aleksey
<VirtualHost *:80>

  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk [NC]
  RewriteCond %{HTTP_HOST} !^$
  RewriteRule ^/(.*)$1 [L,R]

  RailsEnv production
  RailsBaseURI /

      <Directory /srv/www/vhosts/example/current/public>
          Options FollowSymLinks
          AllowOverride None
          Order allow,deny
          Allow from All

        DocumentRoot /srv/www/vhosts/example/current/public

  ErrorLog /var/log/apache2/example_production_error_log
  TransferLog /var/log/apache2/example_production_access_log
  LogLevel warn

Hope that helps.


RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*)$$1

You can use this rack for your app: