Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect all HTTP requests to HTTPS

I'm trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com) to HTTPS (https://www.example.com). How can I do this in .htaccess file?

By the way, I'm using PHP.

like image 254
Cat Avatar asked Nov 03 '10 00:11

Cat


People also ask

How do I redirect a HTTPS request?

The simplest option to perform an HTTPS redirect is to use a redirection service. DNSimple provides a redirector service you can use to redirect HTTPS requests. Using a service is the simplest solution, because it requires little configuration and almost no technical knowledge.


1 Answers

The Apache docs recommend against using a rewrite:

To redirect http URLs to https, do the following:

<VirtualHost *:80>     ServerName www.example.com     Redirect / https://www.example.com/ </VirtualHost>  <VirtualHost *:443>     ServerName www.example.com     # ... SSL configuration goes here </VirtualHost> 

This snippet should go into main server configuration file, not into .htaccess as asked in the question.

This article might have come up only after the question was asked and answered, but seems to be the current way to go.

like image 88
ssc Avatar answered Oct 29 '22 09:10

ssc