How To Safely Redirect /index.php To / Using .htaccess / Apache
Any PHP based software like WordPress, Mambo, Joomla, Drupal, MODx etc. will serve pages both from http://your-site.com as well as http://your-site.com/index.php. This creates duplicate content for search engines, which may then decide to penalize your site for duplicate content. You can safely prevent duplicate content with the following apache code / directive added to your .htaccess file (or in httpd.conf):
RewriteEngine On
#Redirect plain index.php to home page without index.php
RewriteCond %{IS_SUBREQ} false
RewriteRule ^/index\.php$ http://blog.taragana.com [R=301,L]
Replace http://blog.taragana.com with the url of your own site.
What it does is redirect (301 - permanent redirect) all access to /index.php to /
However it does not redirect for internal requests. This is very important because when you are fetching http://blog.taragana.com, Apache actually creates an internal redirect to http://blog.taragana.com/index.php
The RewriteCond above ensures that only external accesses (from browsers, search engine bots etc) are only redirected to the canonical url of the site.
Also it doesn't redirect requests like this http://blog.taragana.com/index.php/archive/java-application-security-through-static-analysis/, which contains index.php as part of the url. Only the exact url http://blog.taragana.com/index.php is redirected to http://blog.taragana.com
Filed under Headline News, How To, Linux, Web, Web Hosting |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |



































