Redirect to HTTPS is missing a slash after the domain name

20,266

Solution 1

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>

Solution 2

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>
Share:
20,266

Related videos on Youtube

keepitnang
Author by

keepitnang

Updated on September 18, 2022

Comments

  • keepitnang
    keepitnang over 1 year

    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>
    
    • LazyOne
      LazyOne about 12 years
      Odd -- should be working just fine. Try RedirectMatch instead: RedirectMatch 301 ^(.*)$ https://www.domain.com$1 -- see if it makes the difference. Also -- modern browsers do cache permanent redirects, so if it failed first time, then browser may still be using old redirect. I suggest clear browser cache and restart it (and/or try another browser).
  • MrWhite
    MrWhite over 3 years
    The (commented out) Redirect directive is missing a trailing slash on the end of the target URL - this will result in a missing slash in the redirected URL.