Apache redirect from one subdomain to another

后端 未结 1 613
清歌不尽
清歌不尽 2021-01-26 12:09

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.         


        
相关标签:
1条回答
  • 2021-01-26 13:08

    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.

    0 讨论(0)
提交回复
热议问题