Tiger Technologies Technical Support

How do I redirect all visitors to the 'www' version of my Web site (or vice versa)?

This page is showing a generic answer. To see a more
specific answer, please type your domain name below:

Our Web servers are configured so that visitors to your Web site will see the same content whether they type example.com or www.example.com in their browser's address bar. You can tell people whichever you think makes more sense or "looks better"; they'll both work.

Some Web site owners want to make sure that only one address is used. For example, if a visitor goes to example.com, you may want them to be automatically redirected to www.example.com, or vice versa.

You can do this with our service. However, keep in mind that setting up redirection can be tricky, especially if you use subdomains or domain name aliases that point to a subfolder of your main site. In fact, it can lead to Web page errors if it is not done correctly.

Therefore, the following changes are not recommended for most users. You should only make these changes if you know how to edit .htaccess files and have a good understanding of the Apache mod_rewrite module. If you aren't comfortable making these changes yourself, you can contact us and ask us to set it up for you.

If you wish to enable this type of redirection, choose one of the following four options. Enter the specified text in an .htaccess file at the top level of your web site.

Keep in mind that these rules will redirect all requests for any file type on your Web site (including images), not just requests for Web pages.

Option 1: Redirecting example.com/dir/anypage.html to www.example.com/dir/anypage.html (same page)

Use this format if you want a request for any URL at example.com to redirect to the same page at www.example.com. (If you want to redirect to the home page of www.example.com, see option 2 below.)

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^example.com [nocase]
RewriteRule ^(.*)         http://www.example.com/$1 [last,redirect=301]

Option 2: Redirecting example.com/dir/anypage.html to the www.example.com home page

Use this format if you want a request for any URL at example.com to redirect to the home page of www.example.com. (If you want to redirect to the same page at www.example.com, see option 1 above.)

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^example.com [nocase]
RewriteRule ^(.*)         http://www.example.com/ [last,redirect=301]

Option 3: Redirecting www.example.com/dir/anypage.html to example.com/dir/anypage.html (same page)

Use this format if you want a request for any URL at www.example.com to redirect to the same page at example.com. (If you want to redirect to the home page of example.com, see option 4 below.)

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^www.example.com [nocase]
RewriteRule ^(.*)         http://example.com/$1 [last,redirect=301]

Option 4: Redirecting www.example.com/dir/anypage.html to the example.com home page

Use this format if you want a request for any URL at www.example.com to redirect to the home page of example.com. (If you want to redirect to the same page at example.com, see option 3 above.)

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^www.example.com [nocase]
RewriteRule ^(.*)         http://example.com/ [last,redirect=301]

Subdomains

If you use subdomains such as blog.example.com, you probably don't want your redirections to interfere with that.

The sample "RewriteCond" lines shown above are correctly written to start with a caret symbol (^), making sure they don't match subdomain hostnames. Be sure to use this format in your own rules to avoid such problems.

Aliases

We offer domain name aliases - an extra domain name that points to a directory of a separate Web hosting account.

If you have a domain name alias that points to a subdirectory (subfolder) of a hosting account, then any redirection rules would be in separate .htaccess files and won't interfere with each other. A .htaccess file at the top level of the site would control the main domain name, and a separate .htaccess file inside the subdirectory would control the aliased domain name. There's no overlap; just be sure to put the rules for each domain name in the correct file.

However, if the aliased domain name points to the top level of your Web site, things get more complicated. The four sample options above won't affect Web requests made via the aliased domain name unless the rules actually mention that domain name, too.

So you'd need to add some extra rules to your .htaccess file to cover this situation. For instance, you could use the following to redirect to the www version of either domain name. This example is the same as option 1 above, and simply adds another RewriteCond and RewriteRule to handle the extra domain name.

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^example.com [nocase]
RewriteRule ^(.*)         http://www.example.com/$1 [last,redirect=301]
RewriteCond %{HTTP_HOST}  ^second-domain.com [nocase]
RewriteRule ^(.*)         http://www.second-domain.com/$1 [last,redirect=301]

Both example.com and second-domain.com need to specified since the same .htaccess file will be used by both domain names.

In the example above, requests for "example.com" and "second-domain.com" are redirected to the "www" version of the original requested domain name. If you prefer to always redirect to one particular name, you can specify that name in the appropriate RewriteRule. For example, if you wanted to redirect requests for "example.com", "second-domain.com" and "www.second-domain.com" to "www.example.com", you could modify the above example to look like this instead:

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^example.com [nocase,OR]
RewriteCond %{HTTP_HOST}  ^second-domain.com [nocase,OR]
RewriteCond %{HTTP_HOST}  ^www.second-domain.com [nocase]
RewriteRule ^(.*)         http://www.example.com/$1 [last,redirect=301]

For more information

Setting up .htaccess rules that use the Apache mod_rewrite module is a complex process. Our htaccess page covers some of the basics, but you might want to do some additional reading. The following pages may be useful:

Search


Related Topics

Domain Name Aliases

Apache .htaccess Files

Moving Web site

Contacting Tiger Technologies

Subdomains