Force Domain to Use "www"

From Lunarpages Web Hosting Wiki
Jump to: navigation, search

How can I always show "www" in front of my domain, even when people just type in mydomain.com?

This is pretty easy to setup by adding this to your .htaccess file:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

Please note, you will need to change mydomain.com to your actual domain name.

Once you have done so, both mydomain.com and www.mydomain.com will both send you to www.mydomain.com. This is usually done for Search Engine Optimization reasons, to prevent the search engines from seeing your one web site as two different web sites.

You can also force your domain to drop the www from the address when typed in, if you would rather have it the other way around. In that situation, you would need to add this to your .htaccess file:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

Please note, you will need to change mydomain.com to your actual domain name.

This will make both mydomain.com and www.mydomain.com send you to just mydomain.com.

Share |
Want to read this in another language?