How To Safely Redirect /index.php To / Using .htaccess / Apache
By Angsuman Chakraborty, Gaea News NetworkSaturday, June 28, 2008
Any PHP based software like WordPress, Mambo, Joomla, Drupal, MODx etc. will serve pages both from https://your-site.com as well as https://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$ https://blog.taragana.com [R=301,L]
Replace https://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 https://blog.taragana.com, Apache actually creates an internal redirect to https://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 https://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 https://blog.taragana.com/index.php is redirected to https://blog.taragana.com
December 22, 2008: 4:13 pm
Hi, $server = $_SERVER['SERVER_NAME']; header(’Location: https://www.’ . $server); but doesen’t work with every page (i.e. https://website.ext/* for every possible string in *). |
December 22, 2008: 4:13 pm
Hi, |
MTBVulture