0

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

  • 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
0

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, Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - 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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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