简体   繁体   English

.htaccess将根域重写为子域

[英].htaccess rewrite root domain to subdomain

i am trying to forward all traffic to my subdomain via htaccess. 我正在尝试通过htaccess将所有流量转发到我的子域。

i am using that .htaccess file: 我正在使用该.htaccess文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule (.*) http://sub.domain.com/$1 [R=301,L]

its working but when i directly write my root domain to the address bar like: http://domain.com it stays on that url. 它的工作,但当我直接将我的根域写入地址栏,如: http : //domain.com时,它将停留在该URL上。 i also want root domain to force forward to sub.domain.com 我也希望根域强制转发到sub.domain.com

how to do that? 怎么做? help me out please. 请帮帮我。

You need to make starting www. 您需要启动www. optional in %{HOST_NAME} . %{HOST_NAME}可选的。

Use this rule: 使用以下规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]

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

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