0

How correctly to rewrite domain to a subfolder with HTTPS ?

This will just redirect all request to subfolder1

RewriteCond %{HTTP_HOST} ^(www.)?example1.com$   
RewriteRule !^subfolder1/ subfolder1%{REQUEST_URI} [L]

If I change to

RewriteCond %{HTTP_HOST} ^(www.)?example1.com$   
RewriteRule !^subfolder1/ https://subfolder1%{REQUEST_URI} [L]

then it will generate a loop

The problem is if I navigate to this url: example.com , then I want it to redirect to HTTPS, and to not change the url to something like: example.com/subfolder1

I want to make the above to work with HTTPS.

Aziz
  • 101

1 Answers1

0

I post my solution in case if someone need it. But if there is a better way then let me know.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule (.*)$ /folder/$1
Aziz
  • 101