Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
laravel
communitycreator

Force redirect from http to https from .htaccess file in Laravel8

Chinweuba Elijah Azubuike

Introduction

It can be annoying when an ssl certificate doesn’t work after purchasing and installing it.

In this shot, we will force the site url to https so your website enjoys the privileges of the ssl.

About .htaccess

An .htaccess file is a high-level configuration within your application running on an Apache server.

With an https installed on your site, your visitors or users will not face the embarrassment of the “This site is not secured” browser message. Moreover, you will be able to interact with APIs hassle-free.

Forcing redirection

Go to .htaccess in your application’s root directory file and paste the code below there.

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The code ensures that all requests to the site are forced to use the https.

RELATED TAGS

php
laravel
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring