简体   繁体   中英

Prevent htaccess from redirecting IP's to www

We have this htacceess code to redirect non-www URL's to 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]

The website has dedicated IP and when we enter the IP address , Rewrite engine will redirect "107.180.56.244" to " https://www.107.180.56.244 " and the site will not load. What should we do?

You can use the following conditions to stop the redirection for HTTP_HOST ip address :

RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTP_HOST} !^www\.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM