Reputation: 275
I migrate my wordpress blog located at blog.example.com to a static page located at example.com/articles.
The path to the blog articles is always the same (/year/month/day/title.html). Therefore I created this rewrite rule for blog.example.com:
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]
This works great and all old article urls are redirected correctly. Now I also want to redirect some rss-feed urls so that I don't have to change them on all the planets I'm subscribed to. So I extended my .htaccess file with the following rules:
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)
But now the last rule matches everything, so "blog.example.com/category/english/feed/" is not redirected to "https://www.example.com/categories/english/index.xml" but to "https://www.example.com/articles/category/english/feed/"
If I remove the last rule the redirect of the three rss-feeds works as expected. How can I make sure that the last rule doesn't match all URLs? Is there a way to tell htaccess to try the rules one by one and stop after the first match? Or how could I change the last rule so that it doesn't match the rss-feed urls?
Upvotes: 0
Views: 657
Reputation: 279
Change the last rewriterule to this:
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !feed/?$
RewriteRule ^(.*)$ https://www.example.com/articles/$1 [R=301,L]
Upvotes: 1