PDA

View Full Version : How to redirect domain.com URLs to www.domain.com URLs


geg2
April 7th, 2007, 05:07 PM
Whenever someone types in "http://domain.com/somedirectory/somepage" , you can easily redirect them to "http://www.domain.com/somedirectory/somepage" OR you can do it the other way around. In any case, you should be consistent with all your URLs.

What does this have to do with SEO? Look around the web and you will find many websites whose PageRank is vastly different for domain.com vs "www.domain.com". How is the search engine supposed to know which URL to rank? By doing a 301 redirect, you remove that possible confusion. Also, by enforcing a consistent URL system, you maximize the PageRank that gets distributed throughout your site from internal and external links.

Below is the code to add to your .htaccess file at the home directory of the website.

First, save a BACKUP copy of your existing .htaccess file. Be sure to change the word DOMAIN into your real domain name and the COM into net, org, us, or whatever your website ends with.

Add the following code to your .htaccess file and upload to the home directory of your website:

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

minnseoelite
April 7th, 2007, 06:03 PM
Already new this one but yea great info for those that don't know. Not only does it consolidate PR but also link popularity as well which can help in rankings as search engines view http://youdomain.com and http://www.yourdomain.com as completly seperate sites

jeremy860
April 7th, 2007, 06:13 PM
knew about this but just forgot to apply it to my resource site. so thanks alot for reminding me.

minnseoelite
April 7th, 2007, 06:16 PM
yea i always make sure to do it before my site is even live so i dont have to wait for the S.E to sort things out

Des
April 9th, 2007, 10:37 AM
I just spent a bit of time dealing with a small issue that was caused by this type of redirect (301). A 301 redirect does not redirect the POST data, only GET. So if you have a form that submits data to a non www url and uses post data your post data will be lost. By adding another condition


RewriteCond %{THE_REQUEST} !POST


above the RewriteRule it will ignore the the rule, and submit and transfer the data properly.

jeremy860
April 9th, 2007, 10:47 AM
^ thanks for that wonderful tip!

geg2
April 9th, 2007, 10:55 AM
Des,

How do I edit my posting at the top of this thread?

fapsian
April 9th, 2007, 10:57 AM
Speaking of .htaccess, would this really be helpful to save bandwidth on an msrs site? I saw this online that, this command enables PHP's built-in transparent zlib compression.

<ifModule mod_php4.c>
php_value zlib.output_compression 16386
</ifModule>

Des
April 9th, 2007, 12:23 PM
geg2: bottom right of your post, there is three buttons, the first is to edit.

Fapsian: Yes that would help save on bandwidth. That php directive can also be set in the php.ini. If you are on a shared server, check with the provider how to configure php per domain/directory.

goki
April 12th, 2007, 02:14 PM
Didn't know that. Thanks

minnseoelite
April 12th, 2007, 04:55 PM
Speaking of .htaccess, would this really be helpful to save bandwidth on an msrs site? I saw this online that, this command enables PHP's built-in transparent zlib compression.

<ifModule mod_php4.c>
php_value zlib.output_compression 16386
</ifModule>

so if i am on a VPS would I paste that into my php.ini file as well or somewhere else

Des
April 15th, 2007, 02:04 PM
zlib.output_compression is a php directive, so just putting


zlib.output_compression 16286


in your php.ini would do the trick

http://ca3.php.net/manual/en/ref.zlib.php for more info about the zlib in php

minnseoelite
April 15th, 2007, 03:10 PM
cool will have to give that a try....does this compress all code on the page as well

mawt
April 16th, 2007, 02:34 AM
I was wondering how to do this! Thankyou.