如何为旧的 AMP 页面制定 301 重定向规则?

问题描述 投票:0回答:2

我的网站使用旧的 AMP 插件,该插件在每个帖子/页面 URL 后添加

/amp/

例如,我的家是:

https://example.com
,“amp”是
https://example.com/amp/

我想知道我可以在

.htaccess
文件中放入什么规则来将所有这些
/amp/
URL 重定向到“正常”页面本身。

例如:

https://example.com/my-article-1/amp/
重定向到
https://example.com/my-article-1/
https://example.com/my-article-2/
重定向到
https://example.com/my-article-2/
,并且每篇文章/页面都会这样做。

我确信无需在

.htaccess
中输入 1000 行 301 个“简单”重定向即可完成此操作!

.htaccess redirect amp-html
2个回答
1
投票

好吧伙计们,

我找到了解决方案,这是你需要告别 /amp/ 的重定向规则:

RewriteEngine On 
RewriteCond %{REQUEST_URI} (.+)/amp(.*)$ 
RewriteRule ^ %1/ [R=301,L]

希望对你有帮助


0
投票

您可以使用根

.htaccess
文件顶部的单个 mod_rewrite 指令来执行此操作(不需要单独的 condition):

RewriteEngine On

# Removes "amp" (or "amp/") from the end of the URL-path
RewriteRule (.*)amp/?$ /$1 [R=301,L]

这会将

example.com/amp
重定向到
example.com/
,并将
example.com/article/amp/
重定向到
example.com/article/
。但像
example.com/amplitude
这样的 URL 没有受到影响。

© www.soinside.com 2019 - 2024. All rights reserved.