ht访问多个重写规则



我将位于 blog.example.com 的WordPress博客迁移到位于 example.com/articles 的静态页面。

博客文章的路径始终相同 (/year/month/day/title.html)。因此,我为 blog.example.com 创建了此重写规则:

RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]

这很好用,所有旧文章网址都被正确重定向。现在我还想重定向一些 rss 提要网址,这样我就不必在我订阅的所有行星上更改它们。所以我使用以下规则扩展了我的 .htaccess 文件:

RedirectMatch 301 ^/category/english/feed https://www.example.com/categories/english/index.xml
RedirectMatch 301 ^/category/deutsch/feed https://www.example.com/categories/deutsch/index.xml
RedirectMatch 301 ^/tag/dev/feed https://www.example.com/tags/dev/index.xml
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]
.htaccess lines 1-8/8 (END)

但是现在最后一个规则匹配所有内容,因此"blog.example.com/category/english/feed/"不会重定向到"https://www.example.com/categories/english/index.xml",而是重定向到"https://www.example.com/articles/category/english/feed/">

如果我删除最后一个规则,则三个 rss 提要的重定向将按预期工作。如何确保最后一个规则与所有网址都匹配?有没有办法告诉htaccess逐一尝试规则并在第一场比赛后停止?或者我如何更改最后一个规则,使其与 rss 提要网址不匹配?

将上次重写规则更改为:

RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteCond %{REQUEST_URI} !feed/?$
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]

最新更新