由网友(快乐的小铅笔)分享简介:在的.htaccess 上的Apache2,你怎么重定向主机的所有资本的变化,以一个规范的小写版本,通过301重定向,并保持安然无恙的路径的其余部分。子域(或没有)应该做的一样好。 此外,通过IP访问应该的没有的重定向。例子:http://Example.com/foo => http://example.com/...
在的.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]
相关推荐
最新文章