本地的http和远程的https。怎么做?

问题描述 投票:0回答:1

如何在.htaccess中编写这个伪代码:

if (ip == "127.0.0.1") or (dns = "localhost") {
  // all to http://
} else {
  // all to https://
}

不久,需要本地的http和远程的https。谢谢。

.htaccess
1个回答
0
投票

你可以用这个:

 RewriteEngine on

 #if http host =127.0.0.1 or localhost
 RewriteCond %{HTTP_HOST} ^127\.0\.0\.1$ [OR]
 RewriteCond %{HTTP_HOST} ^localhost$
 #then do nothing
 RewriteRule ^ - [L]
 #else enforce https
 RewriteCond %{HTTPS} off
 RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.