Redirect traffic from http to https?

Linode Staff

How would I redirect my website's traffic from http to https?

2 Replies

Assuming that you're using the Apache web server, redirects for your website will be controlled by the .htaccess file. By default, the .htaccess file will not exist on your Linode until you have created it in the website's directory. You can create this file by following the directions in our guide page on How to Set Up the htaccess File on Apache .

Once that file has been created, restart the Apache web server and add the following lines to the .htaccess file:

# Redirect HTTPS to HTTP
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It is important to note that you will still require a valid SSL cert in order for the redirect from https to work. HTTPS needs an SSL handshake in order to send any data to the server. This means that without a valid SSL certificate, no redirects will be possible.

Once the above lines have been added to your .htaccess file, you can give Apache another restart and your website redirect should be all set for http.

If you want to do this for every site on your system, make the changes listed above in some more global place…like at the end of /etc/apache2/apache2.conf (on most Linux distros)…instead of each site's .htaccess.

Ditto the cautions about having a valid SSL certificate and restarting Apache when you're done.

-- sw

P.S. You have to make sure that mod_rewrite is loaded or this won't work.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct