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

vbd
  • 127
  • 1
  • 6

1 Answers1

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

SmallClanger
  • 8,947
  • 1
  • 31
  • 45