1

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?

1 Answer 1

2

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.

1
  • thanks! also, for posterity, don't forget to remove https-related rewrite rules in .htaccess files if necessary.
    – J Mac
    May 19, 2013 at 0:26

You must log in to answer this question.

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