我目前正在使用ht.access在我的域名上强制使用WWW前缀.
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.subdomain.mydomain.com,但我想要它没有万维网。在我的子域名..。
当前: http://www.subdomain.mydomain.com Currently: http://subdomain.mydomain.com
是否有任何已知的好编辑对该代码或任何其他.htaccess代码来做我所需要的?
发布于 2013-04-24 04:03:36
你要么明确地知道域名,要么只假设特定数量的TLD(否则就会变得更难)。
显式地说明域:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.domain\.com [NC]
RewriteCond %{HTTPS}s::%1 ^(on(s)|offs)::(.*)$
RewriteRule ^ http%2://%3.domain.com%{REQUEST_URI} [R=301,L]或者只有一个TLD:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\.([^.]+\.[^.]{2,4})$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.[^.]+\.[^.]{2,4})$ [NC]
RewriteCond %{HTTPS}s::%1 ^(on(s)|offs)::(.*)$
RewriteRule ^ http%2://%3.domain.com%{REQUEST_URI} [R=301,L]https://stackoverflow.com/questions/16182138
复制相似问题