为什么我的 .htaccess 重定向不起作用? RedirectMatch 301 "^新闻\/[0-9]+-(.*)" "头条新闻\/$1" [L,R=302]

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

我的 .htaccess 重定向不起作用。

这是我的正则表达式

RedirectMatch 301 "^news\/[0-9]+-(.*)" "headlines\/$1"  [L,R=302]

我使用这个网站来生成它,并且一切似乎都可以在该网站上运行。 https://regex101.com/r/Yq7VSF/1

我们正在迁移网站,“新闻”类别已更名为“头条新闻”。
此外,URL 的最后一个主干开头的数字将被删除。

所以

http://tek.squareballoon.co.uk/news/122-windows-10-the-final-countdown

将成为

http://tek.squareballoon.co.uk/headlines/windows-10-the-final-countdown

regex .htaccess
1个回答
0
投票

RedirectMatch
不支持像
[L,R=302]
这样的标志。这些是
RewriteRule
mod_rewrite
)。所以尝试使用后者:

RewriteEngine On
RewriteRule ^news/([0-9]+)-(.*)$ /headlines/$2 [L,R=301]

您还提到了 301 和 302 重定向,这是非常矛盾的。

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