1

im trying to redirect http to https. I've found a lot answers, but nothing works for me. I dont know why, maybe its a apache2 config error? I tryin it also in the .htaccess and there also nothing happens.

Just this Error:

Bad Request Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.

Here's my Virtual Host File.

#Redirect HTTP TO HTTPS

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]

#VHOSTS


<VirtualHost *:443>
    Servername www.latoya.eu
    ServerAlias latoya.eu www.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:443>
    Servername board.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:443 *:80>
    Servername secure.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:80 *:443>
    Servername static.kritzelpixel.com
    Documentroot /var/www/static.kritzelpixel.com
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>
xMizo
  • 11
  • 1
  • 3

1 Answers1

1

Using "VirtualHost *:80 *:443" or the opposite in the same virtualhost tag is completely incorrect since one virtualhost can't be SSL and not be SSL at the same time.

The fact that Apache HTTPD is not screaming in pain about it is because you "can" use different ports in the same virtualhost but that was certainly not designed to have a SSL port and a non-SSL port together.

So my suggestion is you correct your configuration to look sane, that is, having specific virtualhost *:80 and virtualhost *:443 separately.

In the VirtualHost *:80 entries you can then Redirect / https://example.com/ with the specific hostnames for your case to redirect from 80 to 443 a single line and without the need to use mod_rewrite.

To redirect to SSL mod_rewrite is not needed and overkill.

Briefly:

<VirtualHost *:80>
ServerName example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
#other directives here
</VirtualHost>

And the same with the rest of the names if they have different configurations.

Daniel Ferradal
  • 2,727
  • 1
  • 13
  • 19
  • *:80 and *:443 can both be SSL or non-SSL but by convention port 80 is expected to be non-SSL. – Owen Aug 03 '16 at 23:57
  • syntax allowing it does not prevent it from being a complete aberration which shouldn't be used for coherence shake. At the end, one virtualhost will be SSL or not be SSL, but not both. – Daniel Ferradal Aug 04 '16 at 06:58