Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have requirement to convert all http requests to https requests and append to the server name. For that i have written the following rule which is working for http requests but does not work for https requests.

RewriteRule ^(.*)$ https://%{SERVER_NAME}\{REQUEST_URI} [R]

If I type http:// lvldraspnetserv01, it redirects to https:// as required.

However, if I type https:// lvldraspnetserv01 it does not redirect to https://, causing the certificate to fail.

share|improve this question
You need a certificate for lvdraspnetserv01. In this case the certificate validation happens before the redirect. – matthew Apr 7 '11 at 15:39

Try it like this:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} **Insert current condition here ***
RewriteRule ^(.*)$ https://%{SERVER_NAME}\{REQUEST_URI} [R]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} **Insert current condition here, but for https***
RewriteRule ^(.*)$ https://%{SERVER_NAME}\{REQUEST_URI} [R]
share|improve this answer
I did not understand what do you mean by "Insert current condition here **" and "*Insert current condition here, but for https*" – user77491 Apr 7 '11 at 10:21
Post your complete config above :-). I'll have a look. – Bart De Vos Apr 7 '11 at 16:48

I had the same problem.

Adding the QSA flag solved the problem

RewriteRule ^(.*)$ https://%{SERVER_NAME}\{REQUEST_URI} [R, QSA]

Strange behavior isn't it ? :)^^

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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