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]
尝试类似问题的链接