Alvin Bakker
Alvin Bakker

Reputation: 1526

Forcing https in htaccess gives: The page isn’t redirecting properly

I have a database driven website that needs some entries in the htaccess. To force https I have added line 2 and 3, but it gives an error.

I tried the 2 lines in a different order, but that gives a 500 error. As line 2 and 3 I get: 'Firefox has detected that the server is redirecting the request for this address in a way that will never complete'

The contents of .htaccess is:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteRule ^robots.txt robots.php [QSA,L]
RewriteCond %{REQUEST_URI} !\.(twig)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^eid=(.*)
RewriteRule ^(.*) /index.php?rewrite=$1 [QSA,L]
RewriteRule ^includes/(.*) / [R=301,QSA,L]

What am I doing wrong?

Upvotes: 0

Views: 1813

Answers (1)

semihcosu
semihcosu

Reputation: 346

You can try the method below:

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

This way if your website is using a different port than 80 (which is highly unlikely but worth a try), or something is forcing to redirect your url to example.com instead of www.example.com, it won't be affected.

Upvotes: 1

Related Questions