apache htaccess rewrite rules make redirection loop

Posted by Ali on Stack Overflow See other posts from Stack Overflow or by Ali
Published on 2010-05-06T20:34:23Z Indexed on 2010/05/06 20:38 UTC
Read the original article Hit count: 1136

Hi guys,

Have a very strange problem with Apache .htaccess URL Rewriting and Redirection. Here's my setup: I have a zend application with a single point of entry (index.php) directly under my apache document root (call this the "public" folder). I also have all other public files (images, js, css, etc.) under the public folder. Here, I also have a wordpress blog under the "blog" folder. There's an empty test folder too

The Problem

When I go to mydomain.com/blog, I get redirected to http://www.theredpin.com/blog (correctly), then to http://www.theredpin.com/blog/ (just with an extra / at end), finally to http://theredpin.com/blog/ -- and we're back where we started. The loop continues. What I don't understand is why would wordpress try to remove the www? I'm guessing it's wordpress because my empty test folder acts just fine! PLEASE HELP. I"M REALLY DESPERATE :( Thank you very much

Other things that happen:

When I go to mydomain.com, i correctly get redirected to www.mydomain.com

When I go to www.mydomain.com, i correctly stay where I am

When I go to www.mydomain.com/test or mydomain.com/test, behaviour is correct.

Setup

So my .htaccess file does the following:

  • If there's no www., then add it and do a 301 redirect. Here's the code I use

RewriteCond %{HTTP_HOST} ^mydomain.com [NC]

RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]

  • If the request is NOT for a resource (image, etc.), or the blog, then load zend application by rewriting to index.php

RewriteRule !((^blog(/)?.*$)|(.(js|ico|gif|jpg|jpeg|png|css|cur|JPG|html|txt))$) index.php

Thanks again for all your help!!! Ali

© Stack Overflow or respective owner

Related posts about apache

Related posts about .htaccess