.htacces and https

Hello,

I’m using the following .htaccess and it works pretty well with my webhoster


Options +FollowSymLinks

IndexIgnore */*


RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php

Recently I install a SSL certificate to have and I would like to redirect the http traffics automatically to the https.

my hoster tell me to use that :




RewriteCond %{HTTP_HOST} ^(.*\.)*yourdomain.com$ [NC]

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R]



But when i put those lines ( I replace with my domain) after the other ones it doesn’t work.

I tried several options to modify the .htaccess but nothing seems to work.

Do you have any idea?

If your provider allow you this is the correct method to do it in apache:

https://wiki.apache.org/httpd/RedirectSSL

If this is not possible then you can use mod_rewrite

https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

If you want to control the redirect inside you controller (ie only for some actions) you should use

yii\web\Request::getIsSecureConnection()

http://www.yiiframework.com/doc-2.0/yii-web-request.html#getIsSecureConnection()-detail

Thx you Roberto It’s working !