Apache redirect from one subdomain to another

我的未来我决定 提交于 2019-12-02 18:42:56

问题


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 

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


回答1:


Add the following RewriteRule to your VirtualHost

RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule ^ http://second.example.com [R=301,L]

If you wanted to redirect first.example.com/some/url to second.example.com/some/url:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.example.com$
RewriteRule /(.*) http://second.example.com/$1 [R=301,L]

Recommend you use [R=302] whilst testing the rules to avoid problems with 301s getting cached by your browser.



来源:https://stackoverflow.com/questions/27298333/apache-redirect-from-one-subdomain-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!