简体   繁体   English

.htaccess子域的重定向规则

[英].htaccess redirect rule for subdomains

My site has a lot of subdomains(3rd and 4th levels), for example: 我的网站有很多子域(第3级和第4级),例如:

http://de.site.com/catalog
http://product.de.site.com

and I need to automaticaly redirect all domains with "www", for example 并且我需要自动重定向所有带有“ www”的域,例如

http://www.de.site.com/catalog
http://www.product.de.site.com

to url without "www": 网址不带“ www”:

http://de.site.com/catalog
http://product.de.site.com

Could you please help me with .htaccess rules for this case ? 您能否为我提供有关此情况的.htaccess规则? Please note that this rule must be applied only for 3rd+ levels of domains. 请注意,此规则仅适用于三级以上的域。

Put this code in your DOCUMENT_ROOT/.htaccess file: 将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM