Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从htaccess中的重写规则中排除子域_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 如何从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。我已经玩了

在我的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 %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
现在它会将
domain.com
重定向到
www.domain.com
,但会跳过
sub.domain.com