This post is about supporting your former PATHINFO Permalinks structure (a.k.a. Almost-Pretty-Permalinks), on your new web-site using Pretty-Permalinks.
Redirect 301 /index.php/ https://www.yoursite.com/ RewriteRule . /index.php [L]
These are the lines of Apache’s configuration that must be present in the website’s main .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / Redirect 301 /index.php/ https://www.yoursite.com/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
This case applies to those websites formerly configured to use PATHINFO Permalinks and for which all the old posts and pages have been indexed by the Web Search Engines (Google, Yahoo, Bing, etc) using the former structure that included the HORRIBLE! “/index.php” string in their URIs, i.e.:
https://marcomc.com/index.php/tech/
When these sites finally migrate to the Pretty-Permaling structure, the one that does NOT include the horrifying “/index.php” piece, i.e.:
https://marcomc.com/tech/
it happens that all the search engines’ indexes will result suddently outdated, and that will penalise the sites at least in two ways:
- It will cause a loss of accesses because the back-links to the sites that are present on other blogs or in people’s favourites and bookmarks, or in the search engines’ indexes will be ‘broken’ (old) and the people will be unable to access the pages or posts unless browsing from the homepage.
- It will cause a loss of ranking in the search engines’ databases (S.E.O. perspective) because the sites will result ‘broken‘ (unaccessible) and in some cases may even result like sites with duplicated content because the search engines’ spiders will index the pages as NEW pages (due to their new URIs) and the content will match the caches indexed with the old URIs (at least until the caches expire).
To prevent such mayhem you need to put in place a 301 (permanent) redirection that will tell the search engines that all the requests to URIs containing the ‘/index.php’ bit have to redirected to similar URIs not containing it, i.e.:
Redirect 301 /index.php/ https://marcomc.com/
This string gives instructions to the web server about what to communicate to the Search Engines when a PATHINFO request is received.
Most importantly the 301 redirection will instruct the search engines that the URIs containing “/index.php” have to be considered deprecated and that from now on, the site will not use it anymore. This is fundamental to avoid the search engines to consider the content of the site as a duplicated content.
Secondly you will need to put in place also a generic rewrite instruction that will tell the local web server (Apache) to accept all the incoming requests to URIs with a PATHINFO format and return the content of the new and purged URIs:
RewriteRule . /index.php [L]
This string gives instructions to the web server on what it must to do when a PATHINFO request is received.
I did use these redirection settings for my WordPress blog when I did migrate to a full L.A.M.P. server (GNU/Linux, Apache, MySQL, PHP) from the former Windows Server hosting service running Microsoft IIS and that did not support ‘.htaccess’ files but exclusively PATHINFO directives and for which I did not have access to the server’s core configurations, therefore I was forced to use “/index.php” in my permalinks.
If you did like this post leave a comment in sign of appreciation, ad if you are Facebook please consider to ‘Like’ MarcoMC.com page. Check the FB banner on the right widgets column of this page … ========================================>>