使用查询字符串“?amp"重定向 301 Nginx- AMP Nginx 重定向 [英] Redirect 301 Nginx with query string "?amp" - AMP Nginx Redirect

查看:100
本文介绍了使用查询字符串“?amp"重定向 301 Nginx- AMP Nginx 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Nginx 中制定一个重写规则,在请求的末尾包含?amp",如下所示:

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

这是一个重定向 301.我尝试了一些规则,但它们不起作用,我收到了很多重定向(循环).

It's a redirect 301. I tried some rules, but they do not work, I get many redirects (looping).

不起作用的例子.

rewrite ^/path1/lalala.*? htttp://mywebsite.com/path1/lalala? permanent;

Or

rewrite ^/path1/lalala.*? /path1/lalala? permanent;

我认为问题出在查询字符串?amp"中.你知道如何进行这种重定向吗?

I think the problem is in the query string "?amp". Do you know how to do this redirect?

推荐答案

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.

这篇关于使用查询字符串“?amp"重定向 301 Nginx- AMP Nginx 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆