Skip to content

Instantly share code, notes, and snippets.

@brickgale
Last active January 28, 2022 16:24
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brickgale/f903c2c98ab501d2e604a3c18c3fb115 to your computer and use it in GitHub Desktop.
Save brickgale/f903c2c98ab501d2e604a3c18c3fb115 to your computer and use it in GitHub Desktop.
Laravel force https for Heroku
#add this on public/.htaccess for Laravel
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
web: vendor/bin/heroku-php-apache2 public/
@danielrob
Copy link

Thanks.

+1 this is in line with the official docs which point to this SO

Emphasis:
.htaccess => public/.htaccess

@danielrob
Copy link

Also you can add RewriteCond %{HTTP_HOST} !=localhost so that this doesn't apply to localhost dev :).

@ilhamsj
Copy link

ilhamsj commented Oct 17, 2019

It's work to redirect and good at local, but when i deploy to heroku always force to index.php i'm not recomended to use it, have an idea ? @danielrob

@brickgale
Copy link
Author

@ilhamsj did you add the Procfile on your app directory?

@ilhamsj
Copy link

ilhamsj commented Oct 22, 2019

@brickgale yes i added

@danielrob
Copy link

This was ages ago, but https://laravel.com/docs/5.8/requests#configuring-trusted-proxies (protected $proxies = '*';) was the breakthrough I remember when I was working in this area. Perhaps I used this to force https, but let the trusted proxies declaration sort out the problems with heroku request forwarding.

@ilhamsj
Copy link

ilhamsj commented Oct 22, 2019

@danielrob
Copy link

Nice one!

@brickgale
Copy link
Author

ahh, okay. i was working with lower version of laravel (5.1-5.3) when i made this. Good catch! It was just a middleware problem. Thanks @danielrob!

@lvidal1
Copy link

lvidal1 commented Dec 28, 2019

This is gold. Thanks @brickgale. You saved my weekend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment