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 example.com/blog, I get redirected to http://www.example.com/blog (correctly), then to http://www.example.com/blog/ (just with an extra / at end), finally to http://example.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!
Another weird this is that I can actually go to http://www.example.com/blog/wp-login.php or example.com/blog/wp-login.php and it actually LOADS UP!!!!!
PLEASE HELP. I”M REALLY DESPERATE 🙁 Thank you very much
Other things that happen:
When I go to example.com, i correctly get redirected to http://www.example.com
When I go to http://www.example.com, i correctly stay where I am
When I go to http://www.example.com/test or example.com/test, behaviour is correct.
Setup
So my .htaccess file does the following:
- If there’s no http://www., then add it and do a 301 redirect. Here’s the code I use
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.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
Did you check the settings in WordPress? Log in to admin and check
Settings/Basics(or what it is called in English, I’m using a Swedish translation). There you can configure which URL WordPress is using. If it’s set withoutwww., WordPress will try to redirect.