Redirect 301 Nginx with query string “?amp” - AMP Nginx Redirect

若如初见. 提交于 2021-02-08 06:54:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!