Merging of . htaccess

Asked

Viewed 24 times

1

I’m trying to understand a little about the file . htaccess but I can’t merge two rules.

This is the one I use for the slim framework.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

And that’s the new one I’d like to add after this:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But when I put one after the other the server pops an error. I’ve tried this way too, but so the first rule stops working...

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Would anyone have any suggestions?

1 answer

1

According to the link of the question that Augusto Vasques posted here, I was able to solve my problem as follows:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA]

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

I put the rule of forcing the HTTPS below the first and removed the flag [L] from the first rule as well, so he continues to consider the Abaixos.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.