Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

My site has a normal SSL installed and these are the changes I made in .htaccess

RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} !

But I want to redirect to

share|improve this question

migrated from Aug 26 '12 at 6:31

This question came from our site for professional and enthusiast programmers.

And what have you tried? – Michał Górny Aug 25 '12 at 8:03
Sorry for the incomplete problem. Actually when I open it shows a SSL error. – user1624228 Aug 25 '12 at 9:37

How about something like:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Just note I'm writing it off top of my head; I don't have any server nearby to test it.

edit: added R=301 to make this a permanent redirect since that's what you probably want; and L to make sure following rules won't be applied if one matched already — I just recalled it.

share|improve this answer
PERFECT! Thanks! – user1624228 Aug 25 '12 at 9:54
I've just reordered yours and added the opposite. You could do that yourself ;P. – Michał Górny Aug 25 '12 at 9:56
Haha thanks anyways. I can ask my senior to provide you a Hosting account for free! Just drop me your email and domain at if you need it. :) – user1624228 Aug 25 '12 at 9:57
I've also added 'permanent redirect' flag to the snippet, you'd probably want that to make browser remember the redirect and perform it without asking the server in the future. – Michał Górny Aug 25 '12 at 19:49

Your Answer


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