www to https redirect laravel | laravel htaccess redirect to https

 What about just using .htaccess file to achieve https redirect? This should be placed in project root (not in public folder). Your server needs to be configured to point at project root directory.
<IfModule mod_rewrite.c>  
RewriteEngine On
 # Force SSL    
RewriteCond %{HTTPS} !=on    
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]    
# Remove public folder form URL    
RewriteRule ^(.*)$ public/$1 [L] 
</IfModule>
I use this for laravel 5.4 (latest version as of writing this answer) but it should continue to work for feature versions even if laravel change or removes some functionality. 



Leave a Reply