I switched blogging software (MT to WordPress) on a site and need to redirect requests to http://www.domain1/atom.xml to http://www.domain1.com/feed/atom.

I was using a simple Redirectmatch rule, but realized that it was also redirecting requests made to another site (domain2), that is is hosted by the server, in a subdirectory of domain1, which I do not want to happen (its feed is still at http://www.domain2.com/atom.xml).

How do I get the redirect to only occur for domain1?

I was trying to do the following, but it didn't work.

RewriteCond %{HTTP_HOST} ^www\.domain1\.com [NC]
RewriteRule ^/atom\.xml$  http://www.domain1.com/feed/atom [L,R=301]

Am I close?

Thanks, Rich

2

There are 2 answers

1
awhig On

I figured it out, but I'm not sure why exactly this works. I moved my .htaccess to be:

RewriteCond %{HTTP_HOST} ^www\.domain1\.com [NC]
RewriteRule ^atom\.xml$  http://www.domain1.com/feed/atom [L,R=301]

I removed the slash in front of "atom" in the RewriteRule.

I would think I should have the slash, as I'm tyring to redirect http://www.domain1.com/atom.xml .

It's at the root of the domain...

Oh well. Can anyone explain why this works? Is the string passed to the pattern matching not contain the starting slash?

Thanks, Rich

1
CyberDude On

If you don't do any rewriting for domain2 then a quick fix would be to create a .htaccess file inside its root folder and disable rewriting with RewriteEngine off.

Otherwise you are on the right path with the RewriteCond, it should do the trick. Have you tried adding $ at the end (RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]) / any misspelling / www. vs no www.?