Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.