htaccess redirect not working
Question
I'd like to 301 redirect all .com/language/X
URLs to .com/members/?members_search=X
.
Test case:
http://example.com/language/french
should 301 redirect to
http://example.com/members/?members_search=french
The rule I have set up:
RedirectMatch 301 "^/language/(.*)" "/members/?members_search=$1"
It works correctly when I use a .htaccess
tester. The rule is at the very top of the .htaccess
file. Any ideas?
Solution
Even though you've placed this rule at the top of the .htaccess
file, RedirectMatch
is a mod_alias directive so still runs after other mod_rewrite (ie. RewriteRule
) directives, so you may have a conflict.
Try changing this to a mod_rewrite directive. For example:
RewriteRule ^language/(.*) /members/?members_search=$1 [R=301,L]
NB: No slash prefix on the RewriteRule
pattern when used inside .htaccess
files.
You will likely need to clear your browser cache before testing. Preferably test with 302 (temporary) redirects to avoid potential caching issues.