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

We had once a working setup per .htaccess to redirect a visitor to a canonical URL (for SEO reasons, reduce double content) if she or he visited our rails app:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$1 [L,R=301]

This should essentially mean: If the browser points at something else than, redirect it to by 301. This setup used to work before but is now failing. There are no errors, it just does not work if accessing non-existing content or if accessing URIs provided by the rails application. If I put a static file or php file in RAILS_ROOT/public and access that however the redirect is working.

Our rails application is deployed using passenger. The .htaccess file is placed in RAILS_ROOT/public. It seems to have stopped working since updating one of the components but we cannot exactly tell when that was. The passenger module hasn't been updated since a while so I almast would like to exclude that from the list of causes.

Any clue how to work around this or restore the functionality by going another way?

Using: Gentoo Linux, Apache 2.2.11, Passenger 2.0.6

A passenger upgrade is currently not really an option due to its modified symlink resolution behaviour.

share|improve this question
Do you have any rewrite rules above those for canonicalisation? – earl Dec 10 '09 at 21:37
There's nothing more or less in the .htaccess. – hurikhan77 Dec 11 '09 at 12:02
up vote 1 down vote accepted

I ran into the same issue; looks like either you need to create a separate vhost and redirect or do the rewrite in-app.

See for more details.

Hope that helps you as it did me.

share|improve this answer
We moved the rewrite into the rack stack using [refraction][1]. A seperate vhost was no alternative. [1]: – hurikhan77 Feb 15 '10 at 0:24

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.