Dissident Rage
Dissident Rage

Reputation: 2716

Laravel 5.3 HTTPS Routes

I've read everywhere that Laravel can detect when the user is browsing via HTTPS and uses that to generate routes accordingly, but this appears to be untrue.

I've used a configuration in the AppServiceProvider to force all generated URLs to be prefixed for HTTPS but this only masks an underlying problem.

I have Laravel sitting on an EC2 instance. There is no load balancer and I haven't configured a proxy. This is purely a development instance.

How can I get URLs generated by the route helper to use HTTPS?

Upvotes: 1

Views: 603

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

If a user is on HTTPS page, Laravel's route() helper will generate HTTPS URL. Since Google Chrome is already marks HTTP websites as insecure, it is a good idea is to rewrite all HTTP requests to HTTPS. There are many ways to do that, but as far as I know the best is to setup your web server to do the job.

Sample VH for Apache:

<VirtualHost my.app:80>
   ServerName my.app
   Redirect permanent / https://my.app
</VirtualHost>

<VirtualHost my.app:443>
    DocumentRoot /home/my/public
    ServerName my.app
    ServerAlias my.app
    ServerAlias *.my.app
    SSLEngine on
        SSLCertificateFile conf/ssl.crt/server.crt
        SSLCertificateKeyFile conf/ssl.key/server.key

    <Directory /home/my/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Upvotes: 1

Related Questions