How to force SSL?

In my website I want to force the use of https, so if the user go from a http url it should redirect to a https.

At the moment I have an htaccess inside /frontend/web like this:

RewriteEngine on

RewriteBase /

# Force https

RewriteCond %{HTTPS} !=on

RewriteCond %{SERVER_PORT} ^80

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

# If a directory or a file exists, use the request directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward the request to index.php

RewriteRule . index.php

But I always get "ERR_TOO_MANY_REDIRECTS". I have no idea if I need to do a specific configuration in yii part.

How can I force the use of https without getting this errors?

Sorry this is not an answer but might point you in the right direction, have you looked into URL manager?

Not sure maybe there’s a setting for URL prefix or something.


Thank your for your replies. I’m using VestaCP with nginx as reverse proxy and in this case is necessary do a redirect inside the nginx.conf.

Usually every redirect in the htaccess works in this configuration but this specific redirect must be done inside the nginx.conf.

Thank you anyway