2017-06-19 199 views
0

我将位于blog.example.com的wordpress博客迁移到位于example.com/articles的静态页面。htaccess多个重写规则

博客文章的路径始终是相同的(/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-feed网址,这样我就不必在我订阅的所有星球上改变它们。所以,我伸出我的以下规则.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-feeds的重定向按预期工作。我如何确保最后一条规则不符合所有网址?有没有办法告诉htaccess逐一尝试规则,并在第一场比赛后停止?或者我如何更改最后一条规则,使其与rss-feed url不匹配?

回答

1

改变最后重写规则这样:

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

由于这几乎是完美的。剩下的唯一问题是,这个问题现在重定向为“blog.example.com/category/english/feed”,但不是“blog.example.com/category/english/feed/”。随着斜线,它回落到URL“”https://www.example.com/articles/category/english/feed/“ –

+0

它按预期工作吗? –

+0

@Björn检查我编辑的答案 –