1

Say I have the following Vhost definition in Apache2

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName dummy.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/dummy
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Include /etc/letsencrypt/options-ssl-apache.conf
    ServerAlias www.dummy.com
    SSLCertificateFile /etc/letsencrypt/live/dummy.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/dummy.com/privkey.pem
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:80>
    ServerName dummy.com
    ServerAlias www.dummy.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/dummy
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RewriteEngine on
    Redirect permanent / https://www.dummy.com
</VirtualHost>
</IfModule>

If I type

http://dummy.com

it redirects to

https://www.dummy.com

But if I type

http://www.dummy.com or just www.dummy.com

It redirects to

https://www.dummy.comindex.php/

that is not a valid url.

what in the vhost configuration is causing this? I cannot see where I should look for to debug and solve the issue since the vhost doesn't contains this rewrite rule

Lelio Faieta
  • 221
  • 4
  • 17

1 Answers1

0

The Redirect directive must be:

Redirect permanent / https://www.dummy.com/
  • Note the final slash /.

Modify the configuration file then restart Apache2 or just reload its configuration. And then flush your browser's cache or use new incognito window to do the test.

In addition you do not need RewriteEngine on in order to use the Redirect directive (it is not rewrite rule).

Here is a similar Q&A: Redirect people after SSL is set up

pa4080
  • 29,831
  • 1
    It works fine. Thanks! On the RewriteEngine on consider it a typo. Certbot was trying to setup the redirect using a rewrite rule authomatically and the rule remained there. Thanks again! – Lelio Faieta Feb 04 '20 at 10:28