Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect subfolder to HTTPS

Tags:

I'm trying to write a RewriteRule for my .htaccess file. Specifically, whenever a user accesses a specific subdirectory, I would like it to Rewrite to force an HTTPS connection.

For example, whenever someone accesses: http://www.mydomain.com/subdirectory (and any other sub-directories of that "subdirectory").

I'd like it to rewrite to https://www.mydomain.com/subdirectory

I've tried the following, but it appears to create a loop:

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L] 

Also, this .htaccess file is placed in the root of my domain.

Any ideas on how to modify my RewriteRule?

Many Thanks!

like image 804
Dodinas Avatar asked Jan 21 '11 19:01

Dodinas


2 Answers

I would put this into the domain's root directory:

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/$1 [R=301,L] 
like image 87
Floern Avatar answered Sep 21 '22 04:09

Floern


This work for me, this allow you to redirect to https a specific folder, just add an htaccess file inside of the folder with the following content:

RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
like image 23
jose miguel rivera rodríguez Avatar answered Sep 19 '22 04:09

jose miguel rivera rodríguez