.htaccess重定向IP地址到HTTPS域



我试图将我的网站ip地址重定向到其https域,但我得到错误

Your connection is not private
Attackers might be trying to steal your information from 123.123.123.123 
(for example, passwords, messages, or credit cards). NET::ERR_CERT_COMMON_NAME_INVALID

这是我当前的。htaccess文件

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^123.123.123.123
RewriteRule (.*) https://example.com/$1 [R=301,L]

https是您必须为您的域名购买的证书。所以它会保护你的网站。

以及在谷歌有很多关于强制重定向httphttps的答案。但这根本行不通。你不能强制重定向。它将加载您的网站与 Malitious警告

所以最好购买SSL证书

强制重定向.htaccess

RewriteEngine On 
RewriteCond %{HTTP_HOST}^example.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
或者允许IP
   #Allow List
    order allow,deny
    allow from 123.123.123.123 #specify a specific address
    allow from 123.123.123.123/30 #specify a subnet range
    allow from 123.123.* #specify an IP address wildcard
    deny from all

最新更新