How to redirect all incoming requests to https?

Member

by dana , in category: PHP General , 2 months ago

How to redirect all incoming requests to https?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 2 months ago

@dana 

To redirect all incoming requests to HTTPS, you can add the following code to your .htaccess file on your web server:

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


This code snippet checks if the request is not using HTTPS and then redirects the request to the HTTPS version of the URL. Make sure to test this redirect thoroughly to ensure it's working as expected.