0

I have a strange problem where Apache2 is working correctly for some time and later than I test http://example.com it's not auto-redirecting to SSL anymore.

(to be clear - the foolowing problem is only about one virtualhost that is supposted to redirect to https version of the service, https version of the website is working correctly)

Nothing helps, restarting the host, restarting apache2 and whatnot.

This is my config for the http virtualhost:

<VirtualHost x.x.x.x:80>

    ServerName example.com

    ServerAlias www.example.com

    ServerSignature Off

    DocumentRoot /var/www/non-ssl

    Redirect permanent / https://example.com/

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</IfModule>

<Directory />

    Options All

    AllowOverride All

    Order deny,allow

    Allow from all

</Directory>

   Redirect / https://example.com/



    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    LogLevel warn

</VirtualHost>

I've even put this index.html into /var/www/non-ssl

<meta http-equiv="refresh" content="0; url=https://example.com/" />

And every time I enter http://example.com it gives me 403 Forbidden.

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

Permissions for the index.html file are the following:

-rw-r--r-- 1 root root 69 Jun 5 18:07 index.html

The OS is debian stable.

P.S I am aware of duplicate of Redirect statement in the virtualhost config, but that doesn't matter which of these thing I'll there, it's all the same, always 403.

EDIT: It appears that connecting to http://www.example.com redirects to https://www.example.com But connecting to http://example.com throws 403. I even restarted (stopped and started the service) apache to see if this issue is still present on http://example.com and it is still present.

Kristi
  • 71
  • 1
  • 10
  • 1
    Some other Virtual Host must be getting in front of your example.com. Does the default host have a servername of example.com or is there a *.example.com in an earlier vhost? Earlier means lexically in the /etc/apache2/sites-enabled directory of Debian. – Gerrit Jun 05 '18 at 17:25
  • @user188737 Ihad this virtualhost in the 000-default.conf... ` DocumentRoot /var/www/unknown ServerSignature off ` – Kristi Jun 06 '18 at 16:07
  • have u added an indes page ? like index.php .. you can redirect https://stackoverflow.com/questions/44594799/htaccess-non-www-to-www-and-http-to-https-redirects – Aravinda Jun 06 '18 at 17:27
  • Yes, Debian always makes a defaulthost. I think it catches the example.com because it is also the servername. You could set a different servername on the default host manually. If you just delete it, you get all hostnames directed towards the next virtual host, because Apache will try to answer a request anyway. – Gerrit Jun 06 '18 at 17:49
  • @user188737 Is there any option to tell apache to not respond if domain is not controlled in any virtual host file? – Kristi Aug 09 '18 at 21:01
  • Not that I know of, but you can send out a forbidden or gone. See https://serverfault.com/questions/114931/how-to-disable-default-virtualhost-in-apache2 – Gerrit Aug 10 '18 at 09:25

0 Answers0