我有这个.htaccess文件,但我希望它只在我在现场网站时这样做。
我有什么办法可以:
// if server_name looks like example.com to this
// else dont run this bit
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (auth|register|secure|payment|admin|trading_careers)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(auth|register|secure|payment|admin|trading_careers)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
我尝试使用SetEnvIfNoCase
和IfDefine
但没有成功。不知道是否有可能做我想做的事。
提前谢谢。
EDIT(未来读者的解决方案示例):
// if https is off
RewriteCond %{HTTPS} off
// if server_name like example.com (case insensitive) OR
RewriteCond %{SERVER_NAME} =example.com [NC,OR]
// server_name like www.example.com (case insensitive)...
RewriteCond %{SERVER_NAME} =www.example.com [NC]
RewriteCond %{REQUEST_URI} (auth|register|secure|payment|admin|trading_careers)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
谢谢你的帮助。
答案 0 :(得分:5)
您可以将此条件添加到您的规则中:
RewriteCond %{SERVER_NAME} =www.example.com
答案 1 :(得分:1)
如果您为实际网站使用不同的主机名:
只需检查每种情况下的HTTP_HOST:
RewriteCond %{HTTP_HOST} www.example.com [NC]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (auth|register|secure|payment|admin|trading_careers)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]