Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

http://www.xyz.com -> https://www.xyz.com

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

https://www.xyz.com/docs/ger/abc/1.html ->  http://www.xyz.cm/docs/ger/abc/1.html

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

1 Answer 1

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 http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

share|improve this answer

Your Answer

 
discard

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.