Last Updated: February 25, 2016
·
3.543K
· penguinpowernz

Forward all Apache HTTP traffic to HTTPS

This is a good way to force all traffic to your site to use HTTPS while letting people who forget the 's' in HTTPS still get to your site. Pretend it is at /etc/apache2/sites-available/example.com on a Debian system.

<VirtualHost *:80>
  ServerName example.com
  <Location />
    Redirect permanent / https://example.com/
  </Location>
</VirtualHost>

<VirtualHost *:443>
  ServerName example.com
  DocumentRoot /home/example/example.com

  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/example.com.crt
  SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
  SSLCertificateChainFile /etc/apache2/ssl/example.com.ca-bundle
</VirtualHost>

As you can see the first VirtualHost definition captures all traffic coming in on port 80 for the domain example.com and forwards it to port 443. Easy!

1 Response
Add your response

if you can't modify your virtual hosts file you can try modifying your .htaccess file to redirect the content https://coderwall.com/p/tg3qva

over 1 year ago ·