Logo
My Journal
Blog

Timeline

Blog

How to Force Domains use WWW

Many site owners make the mistake of duplicating their site’s home page. They will have the same content for http://www.domain.tld, http://domain.tld, and http://www.domain.tld/index.html. This will result in lost link value and therefore damage the rankings of the site’s homepage. For example you may have your internal links pointing to http://www.domain.tld but outside sites may be linking to http://domain.tld. Therefore you will be diluting the effectiveness of your site.

If you find many links outside the site pointing to both the non-www and the www version, it may be wise to use a 301 re-write rule so all pages will be redirected to the same url.

How to include the 301 re-write rule in your web site

1. Create a .htaccess file. Open notepad, name and save the file as .htaccess (there is no extension).

2. Place this code in your .htaccess file:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]

RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]

or

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.tld [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
</IfModule>

3. If the .htaccess file already has lines of code in it,

skip a line, then add the above code.

4. Save the .htaccess file

5. Upload the file to the root folder of your server.

6. Test your homepage. Type http://domain.tld, or /www.domain.tld into your browser’s address bar. Any of these urls will now automatically be redirected to http://www.domain.tld

Tip

Whenever exchanging links with other sites or getting incoming links make sure you always use http://www.domain.tld

This will make sure you preserve the link value of your site.

UPDATE: this will also work:

RewriteCond %{HTTP_HOST} ^domain\.tld
RewriteRule (.*) http://www.domain.tld/$1 [R=301,nc]

Bonus
this will redirect index to home page to make the url somehow clean to look at and prevent bots to index 2 similar page with http://domain.tld/index.php and http://domain.tld/

rewritecond %{the_request} ^[A-Z]{3,9}\ /index\.php[^\ ]*\ HTTP/
RewriteRule ^index\.php$ http://www.domain.tld/? [R=301,nc]

right click save as this link for a wordpress plugin

http://log.xmodx.com/files/url_to_full.php.7z

Leave A Comment