Forum Topic: Cleaning-up dead-end permalinks

Forum: .htaccess Forum : Redirecting • Posted by Lloyd Spencer • Updated:

Hello,

From reading the book I decided to implement the following code from the “Cleaning-up dead-end permalinks” part of the book (for WordPress).

RedirectMatch 301 ^/tag/$ http://example.com/
RedirectMatch 301 ^/search/$ http://example.com/
RedirectMatch 301 ^/category/$ http://example.com/

However, I noticed when testing the I still got a 404 with the above code when I visited :

http://example.com/tag

The code only redirected when it had a trailing slash /. I tested your websites including htaccessbook.com and it redirects for both. I got it to work by changing the code to the following and wanted to check this is correct?

RedirectMatch 301 ^/tag$ http://example.com/
RedirectMatch 301 ^/search$ http://example.com/
RedirectMatch 301 ^/category$ http://example.com/

I also wanted to make you aware in case you need to edit this in the next revision of the book.

All the best,

Lloyd

1 Reply to “Cleaning-up dead-end permalinks”

Posted by Jeff Starr

Ah good catch! Here is a better way to do it:

RedirectMatch 301 ^/tag/?$ http://example.com/
RedirectMatch 301 ^/search/?$ http://example.com/
RedirectMatch 301 ^/category/?$ http://example.com/

That’s basically catching any of the dead-end URLs with or without the trailing slash. And yes, thanks to your feedback, I’ll be updating this info in the next version of the book :)