Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and both pointing at the one store. Currently, they have a blog set up at, 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 to, and set up a 301 redirect in the htaccess file to forward traffic from to the new location. The problem is, this also redirects traffic coming in on to Using only the .htaccess, is there away to make redirect to and redirect to a totally different location, say

EDIT: End of last paragraph has been reworded for clarity

share|improve this question
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. => If domain name is different (e.g. then in order to redirect to these rules have to be changed.

UPDATE: Based on updated requirements:

RewriteEngine On
RewriteBase /

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

# rule for
RewriteCond %{HTTP_HOST} [NC]
RewriteRule ^blog(/?|/(.*))$$2 [NC,R=301,L]
share|improve this answer
They already have rules to redirect from to – AlexD Jul 18 '11 at 13:39
@AlexD Based on the description it is my understanding that they both get redirected to 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: => while => 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, needs to go to, but needs to go to a different location, say 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.