0

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.

hurikhan77
  • 567
  • 3
  • 9
  • 22

1 Answers1

1

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 Apache Canonical Rewrite with Passenger (mod_rails) for more details.

Hope that helps you as it did me.

neezer
  • 790
  • 3
  • 10
  • 28
  • We moved the rewrite into the rack stack using [refraction][1]. A seperate vhost was no alternative. [1]: http://github.com/pivotal/refraction – hurikhan77 Feb 15 '10 at 00:24