将子域和目录重定向到另一个子域和目录htaccess

问题描述 投票:0回答:1

我想通过.htaccess将我的一个子域重定向到另一个子域,而我的示例子域URL在下面。

当前URL:http://subdomain.example.com/page/test.html

目标网址:http://testdomain.example.com/page/test.html

.htaccess mod-rewrite url-rewriting
1个回答
0
投票

如果两个子域指向不同的服务器或文件系统的不同部分,那么简单的mod_alias Redirect就足够了。

例如,在.htaccess的根http://subdomain.example.com/中:

Redirect / http://testdomain.example.com/

否则,如果它们指向同一位置,则可能需要使用mod_rewrite来检查所请求的主机名。例如:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule (.*) http://testdomain.example.com/$1 [R,L]
© www.soinside.com 2019 - 2024. All rights reserved.