2

I want that if someone visits http://domain.com that he is redirected to https://domain.com

The .htaccess file is located at /var/www/html with the following content

<ifmodule mod_rewrite.c="">
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</ifmodule>

My apache2.conf contains:

<Directory /var/www/html>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
    SSLRequireSSL
</Directory>

But it does not work, displaying:

Forbidden You don't have permission to access / on this server.

Edit: I removed the SSLRequireSSL line and disabled the cache in Firefox that saves redirections. If I visit http://domain.com it redirects me to https://domain.com. But still it does not do it for subdirectories as well. If I visit http://domain.com/sub I want to be redirected to https://domain.com

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121

1 Answers1

0

The subdirectory I was talking about was a special one... Didn't think that it would matter. It is an owncloud installation which is shipped with an own .htaccess. My .htaccess was overwritten by that one which did not include my rewrite rule.

My second mistake was, like already mentioned that I had the SSLRequireSSL property set. If this is activated it seems that any .htaccess is just ignored.

I also removed the enclosing if statments from the .htaccess like anubhava suggested.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121