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 .htaccess

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=302,L]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} /docs/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=302,L]

Forwarding http to https works (first 2 lines). ->

The folder /docs/ should be redirected to http (lines 3-5) ->

But i get error 310 (net::ERR_TOO_MANY_REDIRECTS) - it seems that I produce an infite loop, but how can I fix my mistake?

R=302 is only for testing will be finally replaced with R=301

share|improve this question
I would get rid of the https to http redirect altogehter. There is really no reason not to server your whole website over https. – Krist van Besien Apr 27 '13 at 7:51
up vote 0 down vote accepted

You are getting an infinite loop. You need a condition that specifically ignores the docs folder on port 80:

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} ! /docs/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=302,L]

I should warn you though: All browsers will throw big warnings if you mix http and https inside the same page. You should be ok if you're only linking to one from the other, however.

See, as always, Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask? and

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.