Php 如何从htaccess中的重写规则中排除子域
在我的htaccess文件中,我有以下代码:Php 如何从htaccess中的重写规则中排除子域,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,在我的htaccess文件中,我有以下代码: RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 我想这样做,如果输入了子域,它不会将其重新写入www.sub.domain.com,而只是sub.domain.com。我已经玩了
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我想这样做,如果输入了子域,它不会将其重新写入www.sub.domain.com,而只是sub.domain.com。我已经玩了好几次了,但似乎都做不好。有什么想法吗?你可以试试这个规则:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
现在它会将domain.com
重定向到www.domain.com
,但会跳过sub.domain.com