How to Normalize URLs & Keep Google Happy

This is something I always (1) forget to do, and (2) forget how to do. Simply add this code (modified for your domain name, of course) to your .htaccess file.

This is important to implement for your search engine ranking. Google, for example, thinks www.domain.com is a different site from domain.com, and this can seriously impact where you rank in Google. There are other ways of doing this, but the below is the only one that doesn’t spit back a 500 error on my server, for some reason.

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

If you want to force ‘www’ on the front end of your URL, switch it up with:

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

[Via DZone Snippets]

You may also like...

Leave a Reply

%d bloggers like this: