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} ^
RewriteRule (.*)$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: to

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

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

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

Popularity: 5% [?]

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 *