Apache: Redirect blog.foobar.com to www.foobar.com

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?




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.

Need Your Help

Password Reset Link : "TO" email address not working

php email mail-form

I have created a password reset function in PHP.

Format phone number using Eval

asp.net formatting label eval

I am trying to format a phone number (stored as string) in a label on an .aspx page using Eval but am having trouble getting it to work. I have tried doing this in the following ways: