如何在Nginx上将URL从。* / amp重定向到。* / amp / 301?

时间:2018-08-24 10:12:04

标签: redirect nginx amp-html

Google为我的/ amp和/ amp /都建立了索引,我想通过将/ amp重定向到/ amp /来解决此问题,但不使用正则表达式来检查结尾是否有斜杠,因为有时URL是/ amp /# html-id

这是示例重定向

https://example.com/post/amp

https://example.com/post/amp/

但不会改变

https://example.com/post/amp/#html-id

服务器是Nginx。

我尝试了这个但没用

rewrite ^/amp$ /$1/ permanent;

这些也不起作用

rewrite ^.*/amp$ /$1/ permanent;

rewrite .*/amp$ /$1/ permanent;

为什么?

更新,似乎$ 1只会捕获括号中的任何内容

更新,我终于用这段代码做到了

rewrite ^/(.*)/amp$ /$1/amp/ permanent;

但是我不确定这是否正确,有人可以确认这是否正确吗?

0 个答案:

没有答案
相关问题