Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm currently running a website which has a 'multi store' feature, which essentially means that the single site handles multiple domains. In this instance, I have domain-a.com and domain-b.com both pointing at the one store. Currently, they have a blog set up at domain-a.com/blog, which can be accessed from both sites.

Recently, we wanted to set up a separate blog for each domain, so we moved the blog from domain-a.com/blog to blog.domain-a.com, and set up a 301 redirect in the htaccess file to forward traffic from domain-a.com/blog to the new location. The problem is, this also redirects traffic coming in on domain-b.com/blog to blog.domain-a.com. Using only the .htaccess, is there away to make domain-a.com/blog redirect to blog.domain-a.com and domain-b.com/blog redirect to a totally different location, say domain-b.com/newBlog?

EDIT: End of last paragraph has been reworded for clarity

share|improve this question

1 Answer 1

up vote 1 down vote accepted

These rules will do the job:

RewriteEngine On
RewriteBase /

RewriteRule ^blog$ http://blog.%{HTTP_HOST}/ [NC,R=301,L]
RewriteRule ^blog/(.*)$ http://blog.%{HTTP_HOST}/$1 [NC,R=301,L]
  1. Place it in .htaccess in website root folder. If placed elsewhere then some small rule tweaking is required.

  2. These rules will work for the domain names you have provided (e.g. domain-x.com => blog.domain-x.com). If domain name is different (e.g. www.domain-x.com) then in order to redirect to blog.domain-x.com these rules have to be changed.

UPDATE: Based on updated requirements:

RewriteEngine On
RewriteBase /

# rule for domain-A.com/blog
RewriteCond %{HTTP_HOST} =domain-a.com [NC]
RewriteRule ^blog(/?|/(.*))$ http://blog.domain-a.com/$2 [NC,R=301,L]

# rule for domain-B.com/blog
RewriteCond %{HTTP_HOST} =domain-b.com [NC]
RewriteRule ^blog(/?|/(.*))$ http://domain-b.com/newBlog/$2 [NC,R=301,L]
share|improve this answer
They already have rules to redirect from domain-a.com/blog to blog.domain-a.com. –  AlexD Jul 18 '11 at 13:39
@AlexD Based on the description it is my understanding that they both get redirected to blog.domain-a.com regardless of the original URL and now Geoff wants to redirect to a blog subdomain but keep domain name part unchanged. This rule does exactly that. If he needs something else (e.g. redirecting to a completely different places: domain-a.com/blog => blog.domain-a.com while domain-b.com/blog => somewhere-else.example.com) then these rules would not work and question needs to be altered to clarify this moment. –  LazyOne Jul 18 '11 at 13:55
Sorry, I didn't pay enough attention and missed using HTTP_HOST in your rules. Thanks for thorough explanation. –  AlexD Jul 18 '11 at 14:07
Sorry, I should have been more clear, domain-a.com/blog needs to go to blog.domain-a.com, but domain-b.com/blog needs to go to a different location, say domain-b.com/newblog for example. I'll amend the question now to clarify this –  Geoff Jul 18 '11 at 14:12
@Geoff Sure, I will update my answer when I see your exact requirements. –  LazyOne Jul 18 '11 at 14:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.