htaccess的重定向规则的子域 [英] .htaccess redirect rule for subdomains

查看:104
本文介绍了htaccess的重定向规则的子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有很多的子域(第3和第4级),例如:

My site has a lot of subdomains(3rd and 4th levels), for example:

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

和我需要automaticaly重定向所有域名以www的,例如:

and I need to automaticaly redirect all domains with "www", for example

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

要URL,而不www的:

to url without "www":

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

能否请你帮我这种情况的.htaccess规则?请注意,这个规则必须只用于域3 +级别的应用。

Could you please help me with .htaccess rules for this case ? Please note that this rule must be applied only for 3rd+ levels of domains.

推荐答案

将这个code在 DOCUMENT_ROOT /的.htaccess 文件:

Put this code in your DOCUMENT_ROOT/.htaccess file:

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]

这篇关于htaccess的重定向规则的子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆