3

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?

5

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/
</VirtualHost>

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]
1
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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