Redirection not working

i wanted to redirect http to https but i cant
i tried using it from htaccess file but i found out that after version 8 its not possible
so i tried to redirect using /etc/apache2/sites-available/conf
and i cant
i can connect to https itself ssl works fine
but i cant redirect http to https
i tried many stuff on the internet
heres my configuration
<VirtualHost *:80>
ServerAdmin email
DocumentRoot /var/www/html/owncloud
ErrorLog {APACHE_LOG_DIR}/error.log CustomLog {APACHE_LOG_DIR}/access.log combined
Redirect permanent /
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<VirtualHost :443>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?secure/(.
) https://%{SERVER_NAME}/secure/$1 [R,L]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/
SSLCertificateKeyFile /etc/letsencrypt/live/

Not sure if the paste of your configuration is complete.

From what I can see there it seems like you have the document root only in your configuration for port 80 and a redirect in your HTTPS configuration (which makes no sense).

So I would recommend the following procedure for enabling HTTPS.

  1. Revert your configuration, so that HTTP works perfectly.
  2. Copy your HTTP config over to the HTTPS config (plus required mod_ssl config)
  3. Make sure HTTPS is working correctly
  4. Create a redirect from HTTP to HTTPS

For a correct HTTP->HTTPS redirect and HTTPS configuration check the Mozilla SSL configuration generator. For example the redirect:

<VirtualHost *:80>
    RewriteEngine On
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

Finally this doesn’t really sound like you have an ownCloud specific problem with the setup. So perhaps it would be better for you to contact a general tech help or apache web server configuration forum.

1 Like

http works without any problem