域重定向到www时如何将www子域重定向到非www [英] how to redirect www subdomain to non-www when domain is redirected to www

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

问题描述

我的主域目前已永久重定向到 www.mydomain.com (非www到www重定向),使用.htaccess如下:

My primary domain is currently permanently redirected to www.mydomain.com (non-www to www redirection), with .htaccess as follows:

RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomain\.com\/" [R=301,L]

RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com$      [NC]

我想知道所有我将要创建的子域,例如blog.mydomain.com,将重定向到非www,例如。 blog.mydomain.com not www.blog.mydomain.com 。每次我创建一个子域并向浏览器输入非www URL时,都会提示重定向循环。

I would like to know how all subdomains that I'll be creating, ex. blog.mydomain.com, will be redirected to non-www, ex. blog.mydomain.com, and not www.blog.mydomain.com. Every time I create a subdomain and enter the non-www URL to the browser, it prompts a redirect loop.

希望您能提供帮助!谢谢! :)

Hope you can help! Thanks! :)

推荐答案

对所有子域都遵循这一规则:

Keep this one rule for all the sub-domains:

# rule for forcing www on main domain
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# rule for removing www on sub domains
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

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

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