Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TechKat's avatar

Forcing Lumen to use HTTPS

How can I tell Lumen to make all routes/requests etc via HTTPS?

Say route('page') = /page

It'll generate a link like: http://example.com/page

How can I get it to generate https://example.com/page instead?

0 likes
5 replies
danielwinter's avatar

if you are creating this route on https it should return https, and redirecting all http sites to https is basically the work of your web server (nginx/apache)

codepotato's avatar

Not intending to bump this old post, but I also have the same issue where on a HTTPS url it's using non https links. Any ideas?

duellsy's avatar

I've got the same issue... just as a belated +1 on this :/

akinyeleolubodun's avatar

You can control it with htaccess. Try this, it should work fine

AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    #Redirect to HTTPS
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I added this to the default htaccess content

    #Redirect to HTTPS
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
2 likes
IshanMahajan's avatar

Instead with a few modification in above answer as the above answer leads to infinite redirect error

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    
    #Redirect to HTTPS
    RewriteCond %{HTTPS} !on [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://api.havemybooks.com%{REQUEST_URI} [L,NE,R=301]
    
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Please or to participate in this conversation.