tags:

views:

40

answers:

1

Hello,

I have a site at blog.foobar.com that I have closed down, and I want any page requested there to be forwarded to www.foobar.com

I want my VirtualHost config to do this for me. I currently have the following lines that does nearly what I want but not exactly:

redirect permanent / http://www.foobar.com

Unfortunately what happens is that if I ask for blog.foobar.com instead of forwarding to www.foobar.com it serves the pages on blog.foobar.com instead.

Is there a way doing this in the VirtualHost config or should I use a .htaccess file instead?

Regards

Steve

+1  A: 

You can use the Redirect directive in the context of either a VirtualHost or a .htaccess file. However, what you probably want is a RedirectMatch:

RedirectMatch permanent (.*)$ http://www.foobar.com$1

With that inside your blog.foobar.com VirtualHost, any request to blog.foobar.com would be directed to the same page on www.foobar.com, ie. blog.foobar.com/my/page would go to www.foobar.com/my/page.

zombat
Thanks! Very informative response. I'll give it a try. Steve
Steve Griff