Reputation: 47
I'm working on a site fixing a few dead links; but I'm having an issue with my RedirectMatch
directives.
RedirectMatch 301 "/treatmentsgenuine-dermaroller(.*)" http://example.com/treatments/genuine-dermaroller-therapy
RedirectMatch 301 "/treatments/genuine-dermaroller(.*)" http://example.com/treatments/genuine-dermaroller-therapy
These are to both correct the badly written link (top) to the page, and redirect requests to the original URL of this page (bottom). The URL had a trademark symbol in the URL, so I removed it for the sake of making it easier to type in/work with.
The only issues is, the site returns error 500 when both of these rules are in place. If I remove the second, it works fine. I've also had the same issue with every other RedirectMatch
I've tried adding to the htaccess.
I've tried adding the [L]
flag, out of a hunch, but this didn't seem to make a positive difference.
Is there anything wrong with this that I can't see?
Are multiple RedirectMatch
directives even allowed?
Upvotes: 0
Views: 1161
Reputation: 47
The best solution I managed to find was
RedirectMatch 301 "((treatmentsgenuine-dermaroller(.)-therapy)|(treatments/genuine-dermaroller(.)-therapy))" http://example.com/treatments/genuine-dermaroller-therapy
This way both variations of the URL are dealt with by the same rule, preventing the redirect loop pointed out to me by @anubhava.
Upvotes: 0
Reputation: 785146
Replace both rules with just this one:
RedirectMatch 301 ^/(treatments)/(genuine-dermaroller)((?!-therapy).*)$ /$1/$2-therapy
Your 2nd rule is also matching target URL and causing a redirection loop.
Upvotes: 1