Joan Nadal Brotat
Joan Nadal Brotat

Reputation: 122

How to exclude folders from HTTPS redirects with .htaccess

I am trying to redirect HTTP requests to HTTPS, but I don't need to redirect all content, I would like to exclude some folders (like the bower_components folder) to avoid loading twice the javascript and css content.

The code that I am using on the .htaccess is:

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

How can I update the .htaccess to exclude folders on the redirect?

Upvotes: 1

Views: 2129

Answers (1)

gioele
gioele

Reputation: 10205

Add more RewriteCond directives to filter the paths that you do not want to redirect. For example

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

Upvotes: 6

Related Questions