.htaccess 强制站点范围的HTTPS,但强制特定目录中的HTTP
我已经找过了,但找不到我需要的答案——或者这对我来说很有效。 我有一个通过htaccess强制使用https的网站。 有1个特定目录必须是http(不能是https) 我的htaccess中有以下内容:.htaccess 强制站点范围的HTTPS,但强制特定目录中的HTTP,.htaccess,https,url-rewriting,.htaccess,Https,Url Rewriting,我已经找过了,但找不到我需要的答案——或者这对我来说很有效。 我有一个通过htaccess强制使用https的网站。 有1个特定目录必须是http(不能是https) 我的htaccess中有以下内容: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_URI} !^/excluded_directory/.*$ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_UR
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/excluded_directory/.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这不会强制在“排除的目录”中使用非https。
我还尝试在“excluded_目录”中添加第二个htaccess,但没有效果。
有人能帮我解决这个问题吗?要将特定目录URL从
https
重定向到http
,您可以在/dir/.htaccess
中使用以下命令:
RewriteCond %{HTTPS} on
RewriteRule ^/?thisDir/.*$ http://example.com%{REQUEST_URI} [NC,L,R]
您也可以尝试使用条件语句来获取更多选项。你应该用这个替换你现在的规则
<If "%{REQUEST_URI} =~ m#^/exclude_directory# && %{HTTPS} == 'on'">
RewriteEngine On
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</If>
<ElseIf "%{REQUEST_URI} !~ m#^/exclude_directory# && %{HTTPS} == 'off'">
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</Else>
重新启动发动机
重写规则^(.*)$http://%{http_HOST}%{REQUEST_URI}[L,R=301]
重新启动发动机
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]