1

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).

2
  • Take a look at the error log.
    – quanta
    Nov 7, 2011 at 13:41
  • RewriteLog /tmp/rewrite.log and RewriteLogLevel 9 (which must be set in the server config) FTW! Nov 7, 2011 at 23:01

1 Answer 1

1

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.

2
  • 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).
    – Paul Voss
    Nov 7, 2011 at 15:07
  • This question seems related: stackoverflow.com/questions/1896321/… ... unfortunately i'm not allowed to edit the apache config. :/
    – Paul Voss
    Nov 8, 2011 at 9:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .