问题
I'm trying to make a rewrite rule in Nginx, that contains "?amp" at the end of the request, like this:
From
http://mywebsite.com/path1/lalala?amp
To
http://mywebsite.com/path1/lalala
It's a redirect 301. I tried some rules, but they do not work, I get many redirects (looping).
Examples that did not work.
rewrite ^/path1/lalala.*? htttp://mywebsite.com/path1/lalala? permanent;
Or
rewrite ^/path1/lalala.*? /path1/lalala? permanent;
I think the problem is in the query string "?amp". Do you know how to do this redirect?
回答1:
rewrite ^/path1/lalala[^?]*\? /path1/lalala permanent;
[^?]*
matches zero or more characters that aren't a question mark, so we make sure to start stripping at the first one.
Then, importantly, the ?
has to be escaped with a backslash because in regexes they have a special meaning.
来源:https://stackoverflow.com/questions/43812339/redirect-301-nginx-with-query-string-amp-amp-nginx-redirect