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

时间:2019-04-02 04:42:51

标签: .htaccess

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

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

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

1 个答案:

答案 0 :(得分: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]