Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed Redmine and so far everything runs smoothly.

Now i want to add a rewrite rule via .htaccess in order to redirect requests from domain.tdl to www.domain.tdl. This is approach works fine with my everyday php projects:

RewriteEngine On
RewriteBase /

# redirect all pages w/o www to www.
RewriteCond %{HTTP_HOST} !^www\.domain\.tdl$
RewriteRule ^(.*)$ http://www.domain.tdl/$1 [L,R=301]

However when i add this to our redmine/public/.htaccess it seems to redirect infinitely (resulting in a timeout/http 500 error).

I tried to look up forums/google for a solution but i only found thousands of contradictory opinions:

  • ruby on rails and .htaccess don't work together
  • ruby on rails and .htaccess DO work together
  • you have to edit your application controller
  • you have to edit your mongel config
  • and so forth...

Am I missing something? I'm not sure i want to edit my application controller and I'm quite certain I don't have access to any mongrel config (managed server hosting).

share|improve this question
Take a look at the error log. – quanta Nov 7 '11 at 13:41
RewriteLog /tmp/rewrite.log and RewriteLogLevel 9 (which must be set in the server config) FTW! – Holger Just Nov 7 '11 at 23:01

It might seem obvious but double check for typos. If the RewriteCond and the RewriteRule don't have exactly the same string for the host then you will end up with infinite redirects. Since you have used placeholders here we can't spot that problem for you.

It's worth using 302 redirects while you are debugging. 301s are cachable and normal web browsers will continue using a 301 redirect they received long after you have changed it on the server. Command line tools like curl and wget don't do this sort of caching.

Do you have a reverse proxy? If so, the Host: header may not be the same on the back end as at the front end.

A timeout is not the same as a 500 error. A redirect loop is not the same as either of them. Try to track down exactly what the response is. Using something like curl -s --include http://www.domain.tdl/ | grep "^HTTP" should do the trick.

share|improve this answer
Thank you for your suggestions. It was indeed a infinite redirection (Status 302). I narrowed the source of the problem down to the variable %{HTTP_HOST} not having the excepted value. It's not "domain.tdl" but something like "1.domain.tdl.anCUSTOMERID.webdav.something.something:81". Not yet sure if it's the "fault" of our hoster or a general problem with Apache Web Server + Phusion Passenger (since I'm a Ruby noob). – AaL Nov 7 '11 at 15:07
This question seems related:… ... unfortunately i'm not allowed to edit the apache config. :/ – AaL Nov 8 '11 at 9:28

Your Answer


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.