我正在尝试编写一个条件,该条件将在实时主机名(domain.com)上强制使用https,但如果在我们的本地测试主机名(domain.local)上则不这样做。
这是我所拥有的:
#force https
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !domain\.local [NC]
RewriteRule ^(.*?)$ https://www.domain.com/$1 [L,R=301]
Run Code Online (Sandbox Code Playgroud)
此条件将重写为https,但还会将domain.local重定向到domain.com
我也尝试过使用这种条件来代替在.local或.com上不做任何事情的中间条件:
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
Run Code Online (Sandbox Code Playgroud)
这是我的htaccess文件的完整内容
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#force ssl
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L,NE]
#rewrite payments subdomain
RewriteCond %{HTTP_HOST} ^payments\.domain\.local$ [NC]
RewriteRule ^(.*)$ https://otherdomain.com/dmi_domain.htm [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^payments\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://otherdomain.com/loanadmin/dmi_domain.htm [NC,R=301,L]
#agents folder to subdomain
RewriteCond %{HTTP_HOST} ^agents\.domain\.local$ [NC]
RewriteRule ^agents/(.*)$ /agents/$1 [L,P]
RewriteCond %{HTTP_HOST} ^agents\.domain\.com$ [NC]
RewriteRule ^agents/(.*)$ /agents/$1 [L,P]
#force …Run Code Online (Sandbox Code Playgroud)