简体   繁体   English

如何使用htaccess将子域(包含所有文件夹和文件)重定向到另一个域?

[英]How to redirect subdomain (with all folders and files) to another domain using htaccess?

I want to redirect subdomain.example.com and all possible URLs accessed by subdomain (like subdomain.example.com/somefolder/somefile.php) to another domain example-two.com. 我想将subdomain.example.com以及该子域访问的所有可能的URL(例如subdomain.example.com/somefolder/somefile.php)重定向到另一个域example-two.com。 Is it possible with htaccess? htaccess有可能吗?

For redirects subdomain.example.com/any-address to example-two.com add this rule on top of your subdomain.example.com .htaccess file 对于将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>

For redirects subdomain.example.com/any-address to example-two.com/any-address add this rule on top of your subdomain.example.com .htaccess file 要将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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM