Redirect http to https by using .htaccess

  • This is a small redirect .htacces script to redirect http to https:


    Code
    1. RewriteEngine On
    2. RewriteCond %{HTTPS} off
    3. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


    (code by Cool - Thanks!)


    Replace domain.tld with your domain/subdomain (e.g. i-mscp.net).

    Edited once, last by UncleSam ().

  • better use:

    Code
    1. RewriteCond %{HTTPS} off
    2. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


    this redirect regardless www...port...ip


    as .htacces overall will slow down allways the best way is to
    implement it to the v-host conf. file with a:
    RedirectPermanent / https://example.com/

  • Yes this is a better way ;) i replace now all my .htaccess redirects and update my first post :P THANKS!

  • grep -i rewrite /etc/apache2/sites-available/00_master.conf

    In my installation there is no /etc/apache2/sites-available/00_master.conf. Guess there have been some changes since then.


    Where would now be the place to achieve a permanent http -> https, ideally one that survives an update?


    Cheers
    Chris

  • In my opinion you should not edit config files which are managed by I-MSCP. You can edit parts of the config using the /etc/apache2/imscp/*.conf files (they are loaded by the main config file for each (sub-)domain).


    If you want to redirect the best would be to be sure to use I-MSCP v1.3.0 or newer because the HSTS feature is implemented now and can be activated (https://i-mscp.net/index.php/T…57-i-MSCP-1-3-0-RELEASED/)


    For the admin panel redirection I personally do the following (in this example the admin interface can be reached using https://admin.domain.tld:4443):

    • I create the domain "domain.tld" inside I-MSCP
    • Adding subdomaind "admin.domain.tld"
    • Enabling SSL for the subdomain
    • Placing an .htaccess file which redirects all requests to port 4443 (normal redirect)

    .htaccess file:

    Code: .htaccess
    1. RewriteEngine On
    2. RewriteRule (.*) https://%{HTTP_HOST}:8443%{REQUEST_URI}

    Benefits (for me):
    I do not like the admin interface proxy plugin - so I do not have to use it.

    Edited once, last by UncleSam: change port from 4443 (pre 1.3.1) to 8443 (1.3.1 and newer) ().

  • With 1.3.0 you can just activate HSTS feature :)

  • With 1.3.0 you can just activate HSTS feature :)

    Maybe I am blind ... but where do I find this feature? :-)


    Forget my post ... found it by editing the SSL certificate. I should have another coffee ...

    i-MSCP 1.5.3 | Ubuntu 18.04