WordPress has a 'template_redirect' feature that will 301 redirect visitors who request a page that does not exist, if it can find a page that closely matches the one originally requested.

For example, if the visitor requests site.com/holidays/holiday_info and this page does not exist, but site.com/vacation/holiday_info does exist, WordPress will 301 redirect the user from the first URL to the second.

This is creating a problem for me when implementing custom htaccess redirects.

The url site.com/portfolio/photography does not exist on my site. I want to set a 301 redirect to send people who request this url to another page, however, site.com/services/photography does exist on my site. WordPress is automatically sending all requests for site.com/portfolio/photography to site.com/sevices/photography, and ignoring my custom htaccess 301 rule. Is there a way I can enforce my rule, without having to disable the 'template_redirect' feature entirely?

  • 2
    The htaccess rules are all handled before WordPress has even loaded, let alone before it does any redirects. If your .htaccess redirect isn't working, the issue must be with the redirect itself, not WordPress. Are you adding your redirects before or after WordPress' .htaccess rules? – Jacob Peattie Mar 6 '19 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.