繁体   English   中英

如何使用.htaccess将root重定向到子域

[英]How to redirect root to sub-domain with .htaccess

我有像example.com这样的域名。 我希望将其上的所有流量发送到sub.example.com。

目前我正在使用此代码,但它发送到example.com/sub:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteCond $1 !^sub
RewriteRule ^(.*)$ /sub/$1 [L] 

有没有办法做到这一点?

我认为你必须使用R标志: Forces an external redirect, optionally with the specified HTTP status code. 细节...

RewriteRule (.*) http://... [L,R] 

只需将以下代码放入.htaccess文件即可。

Redirect 301 / http://sub.domain.com

请记住将http://sub.domain.com更改为您的子域。

康纳

暂无
暂无

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

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