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!
Written by Robert McLeod
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Apache
Authors
nekwebdev
47.02K
petenicholls
33.47K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#