Apache从一个子域重定向到另一个子域 [英] Apache redirect from one subdomain to another
本文介绍了Apache从一个子域重定向到另一个子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道一种从a.example.com永久重定向到b.example.com的方法吗?我还有其他子域需要保持原样.所以:
Does anyone know a way to do a permanent redirect from a.example.com to b.example.com? I have other subdomains that need to remain as they are though. so:
first.example.com -> second.example.com
third.example.com is fine
fourth.example.com is fine
我想在<VirtualHost>
块中执行此操作,而不是.htaccess,以避免重新部署.
I want to do this in the <VirtualHost>
block rather than an .htaccess to avoid having to redeploy again.
任何想法将不胜感激,谢谢
Any thoughts would be appreciated, thanks
推荐答案
将以下RewriteRule
添加到您的VirtualHost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule ^ http://second.example.com [R=301,L]
如果要将first.example.com/some/url
重定向到second.example.com/some/url
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule /(.*) http://second.example.com/$1 [R=301,L]
建议您在测试规则时使用[R=302]
以避免浏览器缓存301错误.
Recommend you use [R=302]
whilst testing the rules to avoid problems with 301s getting cached by your browser.
这篇关于Apache从一个子域重定向到另一个子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文