在 nginx 上重定向 AMP 文件



我正在尝试在nginx上进行重定向,但不幸的是它不起作用。我想实现的是,在移动设备上重定向放大器文件。

我想做什么 :

https://www.example.com/uri-759.html

https://www.example.com/uri-759-amp.html

我作为重定向做了什么

if ($mobile_redirect = perform) {
    redirect ^(.*)(.html)$ $1-amp$2 permanent;
}

我得到什么

https://www.example.com/uri-759-amp-amp-amp-amp-amp-amp-amp-amp.html

有人有解决方案来执行此重定向吗?

可以使用否定的后视断言来避免匹配重写的 URI。

例如:

rewrite ^(.*)(?<!-amp)(.html)$ $1-amp$2 permanent;

有关详细信息,请参阅此文档。

最新更新