How to Force SSL by Redirect to HTTPS Via .htaccess in laravel?





Hello Friends,

Sometimes we buy ssl certified but not use properly. In laravel you can forcefully redirect to https. you have to just put some code in .htaccess file. setup your laravel project in shared hosting then redirect http to https. Secure your site with HTTPS. laravel redirect all traffic to https.

Put following code in bottom of .htaccess file.

# ensure www.

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https

RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteCond %{HTTPS} off

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I hope it can help you...