Global Redirection of port 80 to 443

apache-2.2httpsredirectshell-scripting

I'd like to setup my linux box so that anything hitting port 80 would simply be told ask that of 443. I want it to be regardless of domain, IP or whatever specific details may exist. If it can be requested of port 80, it should be told nope. We do that on 443.

I'll be using Apache on 443 so could bind it to 80 easy enough, but don't see the solution as having to include Apache on port 80.

To be clear, I'm looking for a solution that would require no changes to the vhosts. I understand global redirects that can be passed down with inheritance. That requires vhost changes. I'm looking for something more all-encompassing and less prone to "Oops, I forgot that line and now port 80 is exposing my data unencrypted."

How would you go about solving that problem? iptables, apache, custom shell script with netcat and some magic to make it go SSL?

Best Answer

Try adding this to your httpd.conf;

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

From here - >http://www.sslshopper.com/apache-redirect-http-to-https.html

This uses mod_rewrite so make sure you have that installed beforehand.

The recommended method is as you state to set this in the VHOST file for each site as described here;

http://wiki.apache.org/httpd/RedirectSSL

However, the Apache wiki does document the above rewrite method on more detail;

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS