【问题标题】:How to force http on specific folder in https site如何在 https 站点中的特定文件夹上强制 http
【发布时间】:2026-02-20 03:30:01
【问题描述】:

我有 https 的网站

但我需要具体的文件夹应该是http。

我们如何实现它?

例如 我的网站是

https://www.mywebsite.com

我想folder1/subfolder1应该被强制为http://

例如http://www.mywebsite.com/folder1/subfolder1

我在网上搜索...但最大搜索显示如何强制 httphttps

我试过.htaccess如下:

 try 1.
RewriteRule ^(/folder1/subfolder1)($|/) - [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


 try 2.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/folder1/subfolder1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}  [R=301,L]

但它没有工作..

【问题讨论】:

  • 你没有尝试过使用 .htaccess 吗?
  • @semira 是的,我试过了...请参阅编辑过的问题..

标签: .htaccess http ssl mod-rewrite https


【解决方案1】:

您可以在站点根目录 .htaccess 中使用这些规则:

RewriteEngine On

# force https on everything except /folder1/subfolder1
RewriteCond %{THE_REQUEST} !\s/+folder1/subfolder1[/?\s] [NC]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

# force http on /folder1/subfolder1
RewriteCond %{THE_REQUEST} \s/+folder1/subfolder1[/?\s] [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}  [R=301,L,NE]

确保清除浏览器缓存或使用新浏览器进行测试。

【讨论】: