Wednesday, 17 February 2010

htaccess tutorial - removing index.html for multiple domains

To prevent duplicate issues arising from http://www.domain.com/index.html and http://www.domain.com/ leading to the same page, it is customary to use htaccess to redirect the index.html page to just http://www.domain.com/.

Usually, this can be done by the very simple code:

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

However, this cannot be used in situations where you have multiple domains on the same server space. If you were to use the code above, all the sub-domain index pages would redirect to only one domain. Obviously, this would just annoy visitors and eventually drive them away.

In cases where you have multiple domains on the same server and can thus use only one htaccess file for all your redirections, use the following code:

RewriteBase /
RewriteRule ^index\.php$ / [R=301,L]


This will ensure that your htaccess will redirect visitors to that respective domain's index.