linux - 防止 htaccess 将 IP 重定向到 www

标签 linux apache .htaccess mod-rewrite url-rewriting

我们有这个 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/

相关文章:

php - 在 PHP/Apache 中提供大型 protected 文件

php - 通过 php/linux 在服务器之间同步资源的安全方法

java - 为什么 Apache https 服务器不在 URL 中发送端口号?

linux - 使用 EV SSL 添加自定义 Green BAR MSG

php - mod重写和查询字符串

php - 同一应用程序是否可以有多个 .htaccess 文件?

java - 使用我的应用程序连接到 php .htaccess

.htaccess - mod_rewrite 对于热链接图像无法正常工作

linux - 如何将私钥作为文本传递给 ssh?

c - aligned_alloc返回赋值警告