【发布时间】:2017-11-21 17:12:24
【问题描述】:
我将位于 blog.example.com 的 wordpress 博客迁移到位于 example.com/articles 的静态页面。
博客文章的路径始终相同(/年/月/日/title.html)。因此我为 blog.example.com 创建了这个重写规则:
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]
这很好用,所有旧文章的网址都被正确重定向。现在我还想重定向一些 rss-feed url,这样我就不必在我订阅的所有星球上更改它们。所以我用以下规则扩展了我的 .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-feed 的重定向将按预期工作。如何确保最后一条规则不匹配所有 URL?有没有办法告诉 htaccess 逐个尝试规则并在第一场比赛后停止?或者我如何更改最后一条规则,使其与 rss-feed url 不匹配?
【问题讨论】:
标签: .htaccess mod-rewrite