如何使用 .htaccess 从 HTTPS 重定向中排除文件夹

Joa*_*tat 1 .htaccess https redirect http

我正在尝试将 HTTP 请求重定向到 HTTPS,但我不需要重定向所有内容,我想排除一些文件夹(如bower_components folder)以避免加载两次 javascript 和 css 内容。

我在 .htaccess 上使用的代码是:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)

如何更新.htaccess以排除重定向上的文件夹?

gio*_*ele 5

添加更多 RewriteCond 指令以过滤您不想重定向的路径。例如

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^.*/bower_components/.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)