Wednesday, October 26, 2016

Removing Double Redirects or Redirect Chains form .htaccess files.

If you manage and large site using mod_rewrite or ISAPI_Rewrite 3 you will eventually run into issues maintaining the rewrite rules. After doing a few redesigns or moving things around repeatedly you can end up with situations where one page redirects to another page then another and so on in a chain. This is functional but inefficient, it can have a negative effect on user experience and on SEO value, and makes everything harder to maintain. This tool is a simple script you can pass you .htaccess file through to remove all these multi-step redirects and all pages redirect immediately on the first redirect to the final destination page.

This is a perl program that you will need to save along with a copy of your .htaccess file someplace with Perl installed.

Once saved you can run it by opening a terminal and running the following command:
perl simplify-rewrites filename

The Program will show a summary and a new file will be generated with the de-duping applied. You can use the following to get a list of all the changes for review.
diff -Na --unified=0 rw.txt | less

No comments: