Try it like this, replacing your existing redirect (which is now the 2nd rule below):
# Repeatedly replace all hyphens with %20 - internally
RewriteRule ^language/(.*)-(.*) language/$1\%20$2 [N,DPI]
# Redirect to query string
RewriteRule ^language/(.*) /members/?members_search=$1 [NE,R=301,L]
This achieves the hyphen replacement and redirect to query string in just 1 external redirect. No additional redirect is required. Any number of hyphens are replaced.
This needs to go at the top of the .htaccess
file.
You will need to clear your browser cache. Test first with a 302 (temporary) redirect.
Additional notes:
-
language/$1\%20$2
– the%
needs to be backslash-escaped, otherwise%2
will be seen as an empty backreference, so you’d end up with0
instead of%20
. -
[N,DPI
] – TheN
causes the rewrite engine to immediately start over – creating a loop until all hyphens are replaced. TheDPI
flag is required to discard the original path-info (ie. the part after/language/
in the URL), otherwise this is re-appended (automatically) which could result in a rewrite loop. -
The
NE
flag is required on the second directive (the only change from your original rule) in order to prevent the%20
being doubly encoded as%2520
.