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.

How do I redirect requests coming to http://blog.mysite.com to http://mysite.com/blog?

Reading the apache docs on when not to use the rewrite mod, I tried a simple redirect e.g.

Redirect http://blog.mysite.com http://mysite.com/blog

But when I visit http://blog.mysite.com, it doesn't redirect me. Any suggestions?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Can you do a different <VirtualHost> for blog.mysite.com?

If you can, just put your Redirect config there:

<VirtualHost *:80>
    ServerName blog.mysite.com
    Redirect / http://mysite.com/blog/

If for some reason you still need to piggy-back on the other vhost, or need to handle all subdomains and not just "blog", then use mod_rewrite:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com$
RewriteRule ^/(.*)$ http://mysite.com/%1/$1 [R=301,L]
share|improve this answer
This worked, but I had to comment out ServerAlias *.mysite.com in my mysite.com VirtualHost. That wasn't so bad. The only things it was catching were blog. and www., so I just changed the * to www and was all set! Much thanks! –  Ben McCormack Aug 21 '12 at 1:01

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.