I am currently in the process of assisting in the transition of an older CMS to a newer CMS. As part of that, we have many redirects to set up.

We decided to load these in the .htaccess file, so they can easily be version controlled and modified by non-admins.

The file looks like:

Redirect 301     /product-123.aspx /product-123.html
Redirect 301     /product-456.aspx /product-456.html

However, I came across a seemingly-undocumented and unexpected behavior - redirect 301 is matching substrings. For example, given this rule:

Redirect 301 /page /page.html

It rewrites /page -> page.html as expected, but also rewrites /page/2 -> /page.html/2 and /page/contact -> /page.html/contact, which caused many unexpected edge cases.

Is there a workaround or a way to disable this behavior? Or, if this behavior can not be disabled, what is the best alternative method?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.