Canonical URL solution – redirect non-www to www and index.php to your homepage

Canonical URL issue has always been a headache to the Webmasters and SEOs. But thanks to apache’s mod_rewrite which provide nice escapes for this problem

1. Rewrite all your urls WITHOUT www to WITH www

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

2. Redirect all your index.php and index.html files to homepage or directory root

Options +FollowSymLinks
RewriteEngine on

#rewrite your index.html to homepage 
#eg:  http://www.yourdomain.com/index.html to http://www.yourdomain.com/

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.yourdomain.com/$1 [R=301,L]

#rewrite your index.php to homepage 
#eg: http://www.yourdomain.com/index.php to http://www.yourdomain.com/
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.com/$1 [R=301,L]

** you can do this for default.html or other pages too depending on your default page name.

This entry was posted in SEO, URL Rewriting, Webmaster Issues. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *