开发者

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

开发者 https://www.devze.com 2022-12-25 09:16 出处:网络
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 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开发者_Python百科 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消