Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running an Ubuntu 12.04 Server-based Apache2 server with SSL. I seem to have my configuration correct to achieve SSL connections over port 443, and at first, I did not even configure the server for ANY VirtualHost on port 80.

Now, I would like to configure the server to take any HTTP requests over port 80 and automatically redirect them my port 443 virtualhosts, 100% of the time.

The one tip I am currently attempting is to use a .htaccess file in every directory with the following rule:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</IfModule>

What is the barebones VirtualHost *:80 necessary to achieve correct redirects to *:443?

share|improve this question
up vote 2 down vote accepted

Just use

RedirectMatch ^/(.*)$ https://%{SERVER_NAME}/$1

in the virtual host.

You'd need to set a DocumentRoot to some place so that there's a fallback in case mod_alias is acting up.

share|improve this answer
    
thanks! also, for posterity, don't forget to remove https-related rewrite rules in .htaccess files if necessary. – Jonathan May 19 '13 at 0:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .