0

I'm trying to have a common rewrite rule so that all http traffic gets rerouted to https.

The following is sitting loose in the configuration

RewriteEngine On
   RewriteCond %{HTTPS} off
   RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

But I'm still getting bad request, I'm speaking plain HTTP to an SSL-enabled server port. I also tried with condition

RewriteCond %{SERVER_PORT} !^443$

Is it because rewrite rules must be contained with a virtual host?

1 Answer 1

0

The problem was that the SSLEngine was implicitly turned on for the whole server, so that port 80 itself was expecting https! I created a wildcard virtual host and turned the engine off:

<VirtualHost *:80>
        SSLEngine Off
        TransferLog /var/log/apache2/http_access_log
        ErrorLog /var/log/apache2/http_error_log
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

You must log in to answer this question.

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