How to redirect all incoming requests to https?

Member

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

How to redirect all incoming requests to https?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 6 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.

Related Threads:

How to redirect http requests to https?
How to make https requests in php?
How to redirect all post requests via .htaccess?
How to forward http requests to https with webpack?
How to redirect image requests to another dir via .htaccess?
How to redirect http to https and https://www to https://?