如何在.htaccess中编写此伪代码:
if (ip == "127.0.0.1") or (dns = "localhost") {
// all to http://
} else {
// all to https://
}
不久,本地需要http,远程需要https。 谢谢。
答案 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]