Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ^(.*) http://www.example.com/$1 [L,R=301]

This should essentially mean: If the browser points at something else than example.com, redirect it to www.example.com 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

1 Answer 1

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 http://serverfault.com/questions/106255/apache-canonical-rewrite-with-passenger-modrails 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]: github.com/pivotal/refraction –  hurikhan77 Feb 15 '10 at 0:24

Your Answer

 
discard

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.