Support Center » Knowledgebase » Unix Tips » How to redirect from to

How to redirect from to

Unix Hosting

With Apache's mod_rewrite module, you can do some fancy things by manipulating the url.

On Quadra Hosting, your site can be accessed by either and

This is a handy feature as you don't have to mention the "www" bit when quoting your web site, sometimes you need to make sure everyone is accessing your site with the "www" bit.

One of the things you can do with mod_rewrite is to redirect to, so that when someone types, they will be forwarded to automatically.

This is especially handy if your site keeps a persistent cookie since it's normally based on the domain name.

The rule to do this is quite simple too:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*)
http://www.%{HTTP_HOST}/$1 [L,R]

These lines need to go into a file called .htaccess which resides in your web root directory. If you don't already have one, just create it. It is a simple text file.

To achieve the reverse (that is to redirect to use this rule instead:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www
RewriteRule (.*)$1 [L,R]

Note that you would need to specify the actual in the above case. If you know how to do this using a variable (without hard coding the domain name) please let us know.

Windows Hosting

Users on Windows 2008 (IIS7) are able to rewrite URL's using the URL Rewrite Module. This method is similar to using Apache, but your rules will go in <system.webServer> section of your web.config file. Here is an example Rule that will rewrite non-WWW URL's to WWW:

        <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" />
                <add input="{HTTP_HOST}" pattern="" />
            <action type="Redirect" url="{R:0}" />

Article Details
Article ID: 100
Created On: 25 Feb 2006 12:53 PM
 Login [Lost Password] 
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status