.htaccess 重写规则将 www 附加到 IP 地址 - 如何避免?
.htaccess rewrite rule appends www to IP address - how to avoid?
我的 htaccess 重写规则将 www 附加到我的 ip,所以当我在浏览器中输入时
1.1.1.1
自动变成
www.1.1.1.1
未加载。
如何避免这种情况,但继续将 www
附加到 domain.com
类型的请求?
原规则:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
谢谢!
试试这个。
# force non-www domain
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/ [R=301,L]
这可能是另一种解决方案。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
你可以使用这个.htaccess:
RewriteCond %{HTTP_HOST} !(^www\.|1\.1\.1\.1)
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
或所有 IP 地址:
RewriteCond %{HTTP_HOST} !(^www\.|\d+\.\d+\.\d+\.\d+)
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我的 htaccess 重写规则将 www 附加到我的 ip,所以当我在浏览器中输入时
1.1.1.1
自动变成
www.1.1.1.1
未加载。
如何避免这种情况,但继续将 www
附加到 domain.com
类型的请求?
原规则:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
谢谢!
试试这个。
# force non-www domain
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/ [R=301,L]
这可能是另一种解决方案。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
你可以使用这个.htaccess:
RewriteCond %{HTTP_HOST} !(^www\.|1\.1\.1\.1)
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
或所有 IP 地址:
RewriteCond %{HTTP_HOST} !(^www\.|\d+\.\d+\.\d+\.\d+)
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]