Redirect http to https ends in 400 Bad Request

Servus Community,

I have Nextcloud 20 installed on a Debian 10 system with Apache2 2.4 web server. With Letsencrypt a SSL certificate was installed and the request via the URL prefix https:// also works. However, when entering the page via the URL prefix http://, an error 400 Bad Request is issued.

I’ve been sitting on this for hours now and have tried just about everything I can find in terms of possible solutions.

The redirect statement was done in the Virtual Host Configuration by certbot:

<VirtualHost *:80>
     ServerAdmin towi@domain.de
      DocumentRoot /var/www/domain.de/cloud/nextcloud
     ServerName cloud.domain.de

     ErrorLog ${APACHE_LOG_DIR}/cloud.domain.de_error.log
     CustomLog ${APACHE_LOG_DIR}/cloud.domain.de_access.log combined

	SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/cloud.domain.de/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/cloud.domain.de/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/cloud.domain.de/chain.pem

RewriteEngine on
RewriteCond %{SERVER_NAME} =cloud.domain.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I also added the following instruction but it did not change anything either:

RedirectPermanent / https://cloud.domain.de/

The .htaccess file is unchanged. Other web projects (Wordpress) work fine with above changes.

Can anyone help localize the problem or know what the problem is?

Thx & Bye Tom

Servus Community,

I fixed the problem, there were still errors in the vhost configuration. Now it works and an http request is automatically redirected to https. That’s how it should be…

Thx & Bye Tom

1 Like