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

I'm using the following .htaccess to redirect or to

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

If the address is I would to redirect to https instead of http. How to do that?

Thank you.

share|improve this question
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

# check if https if off and check if the requested uri ends with login
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
share|improve this answer
I tried your example and it's not forwarding to https. If I enter "" it redirects to "";. Do I miss something? – Tom Feb 28 '13 at 17:45
You can try replacing: RewriteCond %{HTTPS} off by this: RewriteCond %{SERVER_PORT} ^80$ – Jose Robinson Mar 1 '13 at 20:19
Tried it but it's also not redirecting to https. What else could I try? – Tom Mar 2 '13 at 21:49
Are you testing on local? Did you do a test on a remote server (ie: a hosting server)? I'm asking you because I believe that you have a configuration issue. – Jose Robinson Mar 9 '13 at 14:02
I'm testing it on a hosting server. What kind of configuration issue could it be? – Tom Mar 21 '13 at 10:23
 RewriteRule   ^login  https://%{HTTP_HOST}%{REQUEST_URI}  [R,L]
share|improve this answer

You can force the user to browse your website through a Secured Sockets Layer (SSL) by writing these lines in your .htaccess file.

Engine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$$1 [R]

This being said, you will have to create some certificates, and make some other manipulations to handle it, otherwise each time you will try to connect, you will have an ugly 107 error (net::ERR_SSL_PROTOCOL_ERROR) : Error with SSL protocol. Just search on Google "how to make server https", and there is a bunch of relevant results.

share|improve this answer
Can you please improve the answer by adding the line for /login - in the question. – Akber Choudhry Mar 4 '13 at 20:20
@akber-choudhry It actually works with any adress the user may request, which includes /login. – guillaume Mar 5 '13 at 1:11

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.