I have a website that actually has this URL when someone search anything
/search?searchword=KEYWORD&searchphrase=all
and i would like to redirect it to the new ones:
/newsearch?q=KEYWORD
basically, preserve the KEYWORD param and rewrite the URL
I’ve tried RewriteRule ^search?searchword(.*)$ /newsearch?q=$1 [L,QSA]
but it doesn’t work, nothing happens.
Thanks.
2
Answers
Could you please try following, based on your shown samples only. You need to catch string after
searchword=
and before&
into back reference(temp memory) to fetch it while doing rewriting url.When I check this with
curl
command if this is rewriting correctly or not and it looks fine there.Your rule doesn’t work because you are using
RewriteRule
directive to test querystring. You need to match against%{QUERY_STRING}
or%{THE_REQUEST}
as mentioned in the answer by @RavinderSingh13.