How Do You Start a Laragon Website as https://?


  • | 286 points

    I have SSl enabled in Apache and added the laragon.crt to the trust store. When I open www > sitename.test, I would like to have it open as https://sitename.test. I edited the auto.sitename.test.conf file to add https:// to the define SITE statement, but this didn't open the site in https://. I can manually type https://sitename.test in the browser address bar and that does work. What do I need to do to automate this?


  • | 17 points

    I want to ask same question too. Waiting an answer from another person.


  • | 16270 points

    @nitrobob according to SO - How to automatically redirect HTTP to HTTPS on Apache servers? the recommended way is via .conf files. We cant use this method as Laragon will overwrite these .conf files automatically. Further down is the alternative way with .htaccess, I created the following as a demo, which works with the index.php on localhost. Create the .htaccess file and save it in C:\laragon\www. Then open http://localhost.

    <IfModule mod_rewrite.c>
    
        SetEnv HTTP_MOD_REWRITE On
        RewriteEngine On
    
        RewriteCond %{HTTPS} !=on
        # This checks to make sure the connection is not already HTTPS
    	
        RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
        # This rule will redirect users from their original location, to the same location but using HTTPS.
        # i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
        # The leading slash is made optional so that this will work either in
        # httpd.conf or .htaccess context
    
        # add other rules as required.....
    </IfModule>
    

    If you open developer tools you will see the page is redirected

    0_1631964832047_upload-d5776a96-c694-4db1-948f-3235a3d4b373

    You will also see the padlock.

    0_1631964971066_upload-49dd6ec0-80c4-4e19-b44a-ac320ba31120

    Feel free to modify the file for your project. Put the file in the entry point of your project (either the root or the public folder) and all HTTP requests will be re-routed to HTTPS. If your project already has a file then add the above rule before the other rules.

    I hope this helps.


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.