5

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

Example http://domain.com/index.html it redirect me to http://www.domain.comindex.html

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

It's work with http://www.domain.com/index.html

Here is my httpd.conf

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

<VirtualHost *:443>
  DocumentRoot /var/www/domain/
  ServerName www.domain.com
  SSLEngine on
  SSLCertificateFile ssl.crt
  SSLCertificateKeyFile ssl.key
</VirtualHost>
  • 2
    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). – LazyOne Apr 24 '12 at 13:10
2

Change to this and try it, notice only two VirtualHost

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

<VirtualHost *:443>
  DocumentRoot /var/www/domain/
  ServerName www.domain.com
  SSLEngine on
  SSLCertificateFile ssl.crt
  SSLCertificateKeyFile ssl.key
</VirtualHost>
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 domain.com
    ServerAlias *.domain.com
#   Redirect 301 / https://www.domain.com
    RedirectMatch permanent /(.*) https://www.domain.com/$1
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.