通用htaccess的重定向到WWW非www [英] Generic htaccess redirect www to non-www

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

问题描述

我想 www.example.com 重定向到 example.com 。下面htaccess的code使这种情况发生:

 的RewriteCond%{HTTP_HOST} ^ WWW \\ .EXAMPLE \\ .COM [NC]
重写规则^(。*)$ http://example.com/$1 [L,R = 301]

但是,有没有办法做到这一点的一种通用的方式没有硬编码的域名?


解决方案

  RewriteEngine叙述在
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ WWW \\。(。*)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]

相同,除了这一个迈克尔的作品:P

I would like to redirect www.example.com to example.com. The following htaccess code makes this happen:

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

But, is there a way to do this in a generic fashion without hardcoding the domain name?

解决方案

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Same as Michael's except this one works :P

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

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