在.htaccess,如何重定向主机名非小写版本 [英] In .htaccess, how to redirect non-lowercase versions of hostname
本文介绍了在.htaccess,如何重定向主机名非小写版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在的.htaccess
上的Apache2,你怎么重定向主机的所有资本的变化,以一个规范的小写版本,通过301重定向,并保持安然无恙的路径的其余部分。子域(或没有)应该做的一样好。
此外,通过IP访问应该的没有的重定向。
例子:
-
http://Example.com/foo
=>http://example.com/foo
-
http://A.example.com/foo
=>http://a.example.com/foo
-
http://A.EXample.com/foo?bar
=>http://a.example.com/foo?bar
-
http://208.67.222.222/foo
=>http://208.67.222.222/foo
解决方案
#确保主机仅是小写(或IP地址)
的RewriteCond%{HTTP_HOST}!^(。+ \)?例如\ .COM $
的RewriteCond%{HTTP_HOST}!^ [\ D \] {7,15} $
重写规则^(。*)$ $ {小写:%{HTTP_HOST}} / $ 1 [R = 301,L]
In .htaccess
on Apache2, how do you redirect all capitalization variations of a hostname to a canonical lowercase version, via 301 redirect, and keeping the rest of the path unharmed. Subdomains (or not) should do the same as well.
Additionally, accessing via an IP should not redirect.
examples:
http://Example.com/foo
=>http://example.com/foo
http://A.example.com/foo
=>http://a.example.com/foo
http://A.EXample.com/foo?bar
=>http://a.example.com/foo?bar
http://208.67.222.222/foo
=>http://208.67.222.222/foo
解决方案
# Make sure hostname is lowercase only (or an IP address)
RewriteCond %{HTTP_HOST} !^(.+\.)?example\.com$
RewriteCond %{HTTP_HOST} !^[\d\.]{7,15}$
RewriteRule ^(.*)$ ${lowercase:%{HTTP_HOST}}/$1 [R=301,L]
这篇关于在.htaccess,如何重定向主机名非小写版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文