Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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重定向到子域中的www_Php_.htaccess_Redirect_Subdomain - Fatal编程技术网

Php .htaccess重定向到子域中的www

Php .htaccess重定向到子域中的www,php,.htaccess,redirect,subdomain,Php,.htaccess,Redirect,Subdomain,我无法将example.com重定向到www.example.com,并且它的子域重定向到www.test.example.com到test.example.com 目前我正在使用这个: RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} !^([^\.]+)\.([^\.]+)\.([a-z]{2,4})$ RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L] 主域需要一条规

我无法将
example.com
重定向到
www.example.com
,并且它的子域重定向到
www.test.example.com
test.example.com

目前我正在使用这个:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.([^\.]+)\.([a-z]{2,4})$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

主域需要一条规则,子域需要另一条规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.[^.]+\.[^.]+\.([a-z]{2,4})$
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,NE,L]

尝试类似问题的链接