0

Hi I'm trying to force ssl on traffic to my domain however it is failing for anything below the root level ie:

http://my.domain/application returns as: https://my.domainapplication

so the root slash is missing in the redirect. I've tried a 301 redirect and conditional rewrites and both yield the same result.

The latest version of my virtualhost for port 80 is:

ServerName my.domain
ServerAlias www.my.domain
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I tried

Redirect / https://my.domain/

and that produced the same result.

Can anyone advise where I'm going wrong?

Thanks

1 Answer 1

2

Try this:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I suspect the != is necessary.

Also, ensure you allowed .htaccess with:

AllowOverride all

in httpd.conf

Alternatively, you can also try this rewriterule that doesn't use http_host:

RewriteRule ^(.*) https://your_server.com/$1
5
  • Thank you so much. The first was the answer. It was the != as you suspected. I must admit I'm still not sure what is going on so if you could explain it it would be great. Will check out tomorrow when a little more sober :D Jan 15, 2016 at 23:01
  • Good to see it solved your problem! I'll see if I can edit my answer with more details. Jan 15, 2016 at 23:03
  • I actually don't really know why your first one wasn't working. I saw at least 1 other person who used RewriteCond %{HTTPS} off and had it work. I might have been your use of (.*) instead of ^ for the rewrite rule. I'm not entirely certain. Jan 15, 2016 at 23:09
  • Thanks Stephen. The ^ works. Because of what you had said I went back then to the .* and that works too. I copied that from my config and renamed the domains so don't know why I couldn't see it earlier. I can only guess I must have done something wrong. Jan 15, 2016 at 23:26
  • Either way, I'm glad I could help! Jan 15, 2016 at 23:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .