5

I just set up HTTPS on my server, and I have an issue with redirect permanent.

Example: http://example.com/index.html redirects me to http://www.example.comindex.html.

The / (tail ending slash) is missing and I can't figure out how to fix it.

It works with http://www.example.com/index.html.

Here is my httpd.conf

<VirtualHost *:80>
  ServerName example.com
  Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:80>
  ServerName www.domain.com
  Redirect permanent / https://www.example.com/
</VirtualHost>

<VirtualHost *:443> DocumentRoot /var/www/example/ ServerName www.example.com SSLEngine on SSLCertificateFile ssl.crt SSLCertificateKeyFile ssl.key </VirtualHost>

MrWhite
  • 43,224
  • 4
  • 50
  • 90
Clem
  • 51
  • 1
  • 1
  • 2

3 Answers3

2

Change to this and try it, notice only two VirtualHost

<VirtualHost *:80>
  ServerName example.com
  ServerAlias *.example.com
  Redirect permanent / https://www.example.com/
</VirtualHost>

<VirtualHost *:443> DocumentRoot /var/www/example/ ServerName www.example.com SSLEngine on SSLCertificateFile ssl.crt SSLCertificateKeyFile ssl.key </VirtualHost>

MrWhite
  • 43,224
  • 4
  • 50
  • 90
Anthony Hatzopoulos
  • 1,378
  • 10
  • 18
1

I had that same issue, and don't know why it is failing either. I was able to work around it using this instead:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
#   Redirect 301 / https://www.example.com
    RedirectMatch permanent /(.*) https://www.example.com/$1
</VirtualHost>
MrWhite
  • 43,224
  • 4
  • 50
  • 90
el_timm
  • 11
  • 1
0

Example: http://example.com/index.html redirects me to http://www.example.comindex.html.
The / (tail ending slash) is missing and I can't figure out how to fix it.

This will happen if you are missing the trailing slash from the end of the target URL-path on the Redirect directive, when the slash is included on the source URL. For example: Redirect / https://www.example.com or Redirect /subdir/ https://www.example.com/subdir - the slashes need to match.

However, this is not the case with the directives as posted in the question, since you appear to be including the trailing slash on the target URL. This should work as intended, and there is little that can override this. It is quite likely you are seeing a cached response due to an earlier erroneous "permanent" redirect. 301 redirects are cached persistently by the browser by default.

Test first with 302 (temporary) redirects to avoid potential caching issues.

MrWhite
  • 43,224
  • 4
  • 50
  • 90