【问题标题】:How to redirect subdomain (with all folders and files) to another domain using htaccess?如何使用 htaccess 将子域(包含所有文件夹和文件)重定向到另一个域?
【发布时间】:2019-12-16 03:32:43
【问题描述】:

我想将 subdomain.example.com 和子域访问的所有可能的 URL(如 subdomain.example.com/somefolder/somefile.php)重定向到另一个域 example-two.com。 htaccess 可以吗?

【问题讨论】:

    标签: .htaccess subdomain addon-domain


    【解决方案1】:

    对于将 subdomain.example.com/any-address 重定向到 example-two.com,请将此规则添加到您的 subdomain.example.com .htaccess 文件的顶部

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
        RewriteRule (.*) http://example-two.com/ [R=301,L]
    </IfModule>
    

    对于将 subdomain.example.com/any-address 重定向到 example-two.com/any-address 将此规则添加到您的 subdomain.example.com .htaccess 文件的顶部

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
        RewriteRule (.*) http://example-two.com/$1 [R=301,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      相关资源
      最近更新 更多