We must redirect from this URL:
https://www.ourdomain.com/event/just-an-event-600922?test=620c3c875ceb1ae584920c04d02bc083
to the same without the query string:
https://www.ourdomain.com/event/just-an-event-600922
We’ve tried with this combination of RewriteCond and RewriteRule:
RewriteCond %{QUERY_STRING} ^test=([A-Za-z0-9]+)$
RewriteRule ^event/just-an-event-600922$ https://www.ourdomain.com/event/just-an-event-600922 [L,R=301]
But it apparently causes an infinite loop. Any idea how to fix this?
2
Answers
You can remove
R=301
, then it will not redirect browser to the new URL, but rather rewrite it internally and call your web application with the new query string.another option is to simplify it:
You were close, but you’re missing the
?
at the end. Actually, the query string is appended automatically when it comes to the redirection, resulting in a loop. By using?
, you kind of reset the query string.So, your solution:
Note 1: you don’t need to match and remember the
test
value by using parenthesis, since you don’t use it.Note 2: you can match the RewriteRule so that you don’t need to write it one more time for the redirection target (notice the
?
at the end, which is really the point to your initial question here).