我们有这个 htacceess 代码将非 www URL 重定向到 https://www :
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
网站有专用 IP,当我们输入 IP 地址时,重写引擎会将“107.180.56.244”重定向到“https://www.107.180.56.244”,网站将不会加载。 我们该怎么办?
最佳答案
您可以使用以下条件来停止对 HTTP_HOST ip 地址的重定向:
RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTP_HOST} !^www\.
关于linux - 防止 htaccess 将 IP 重定向到 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195118/