Error when URI does not contain "/" (trailing slash)

165 views
Skip to first unread message

Ariel

unread,
Dec 27, 2009, 11:46:07 PM12/27/09
to Phusion Passenger Discussions
I have set up a default Rails application that uses the RailsBaseURI
directive, which is set to "/hello". The behavior that I expect from
Apache mod_dir is:
1. Rewrite "/hello" URIs that do not contain a trailing slash to "/
hello/"
2. Serve the index.html in the "hello" directory

But that is not what I am experiencing. Apache seems to hand the
request off to Passenger before rewriting the URI. Passenger then
sends the request into the Rails dispatcher. Since there is no root
route defined, Rails reports a 404 Error
[ActionController::RoutingError (No route matches "" with
{:method=>:get}):].

Is there something that I do not understand about the interaction
between apache and passenger? Is there a configuration that I am
missing somewhere?

Platform
======
Mac OS X
Rails 2.1.2
Apache/2.2.13 (Unix)
passenger 2.2.7

Symlink
======
/Library/WebServer/Documents/hello -> /projects/hello/public/

Configuration
==========
<Directory /Library/WebServer/Documents/hello>
Options -MultiViews
RailsEnv development
RailsBaseURI /hello
</Directory>

Full Stack Trace
============
Processing ApplicationController#index (for ::1 at 2009-12-27
22:55:11) [GET]
Session ID:
BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--8fbbb41e75a863c35db18203eac31a4ed2dc840e
Parameters: {}

ActionController::RoutingError (No route matches "" with
{:method=>:get}):
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
routing/recognition_optimisation.rb:67:in `recognize_path'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
routing/route_set.rb:385:in `recognize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:148:in `handle_request'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:107:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:104:in `synchronize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:104:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:120:in `dispatch_cgi'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/
dispatcher.rb:35:in `dispatch'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
railz/request_handler.rb:50:in `process_request'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_request_handler.rb:207:in `main_loop'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
railz/application_spawner.rb:374:in `start_request_handler'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
railz/application_spawner.rb:332:in `handle_spawn_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
utils.rb:184:in `safe_fork'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
railz/application_spawner.rb:330:in `handle_spawn_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:352:in `__send__'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:352:in `main_loop'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:196:in `start_synchronously'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:163:in `start'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
railz/application_spawner.rb:209:in `start'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
spawn_manager.rb:262:in `spawn_rails_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server_collection.rb:126:in `lookup_or_add'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
spawn_manager.rb:256:in `spawn_rails_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server_collection.rb:80:in `synchronize'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server_collection.rb:79:in `synchronize'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
spawn_manager.rb:255:in `spawn_rails_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
spawn_manager.rb:154:in `spawn_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
spawn_manager.rb:287:in `handle_spawn_application'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:352:in `__send__'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:352:in `main_loop'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/
abstract_server.rb:196:in `start_synchronously'
/Library/Ruby/Gems/1.8/gems/passenger-2.2.7/bin/passenger-spawn-
server:61

Hongli Lai

unread,
Dec 28, 2009, 4:20:50 AM12/28/09
to phusion-passenger
On Mon, Dec 28, 2009 at 5:46 AM, Ariel <ar...@arielvalentin.com> wrote:
> I have set up a default Rails application that uses the RailsBaseURI
> directive, which is set to "/hello". The behavior that I expect from
> Apache mod_dir is:
> 1. Rewrite "/hello" URIs that do not contain a trailing slash to "/
> hello/"
> 2. Serve the index.html in the "hello" directory
>
> But that is not what I am experiencing. Apache seems to hand the
> request off to Passenger before rewriting the URI. Passenger then
> sends the request into the Rails dispatcher. Since there is no root
> route defined, Rails reports a 404 Error
> [ActionController::RoutingError (No route matches "" with
> {:method=>:get}):].
>
> Is there something that I do not understand about the interaction
> between apache and passenger? Is there a configuration that I am
> missing somewhere?

This behavior is intentional. We actually went through great pains to
ensure that mod_dir doesn't do this to Phusion Passenger-served apps;
multiple people filed bug reports because mod_dir added a trailing
slash and they expected it not to.

What are you doing and why do you expect it to add a trailing slash?

You can disable Phusion Passenger for specific URIs with <Location>
blocks and PassengerEnabled off.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Ariel

unread,
Dec 28, 2009, 12:44:33 PM12/28/09
to Phusion Passenger Discussions
Hongli,

Thank you for your prompt reply. Sorry to ask yet another question
about this topic. I was unable to find any content about this subject
that made me feel like it was directly related to my problem.

HL> why do you expect it to add a trailing slash?
---------------------------------------------------------------
I just thought that is what mod_dir does according to the httpd
documentation <http://httpd.apache.org/docs/2.0/mod/mod_dir.html>

>> Description: Provides for "trailing slash" redirects and serving directory index files
>> Typically if a user requests a resource without a trailing slash, which points to a directory, mod_dir redirects him to the same resource, but with trailing slash for some good reasons:
>> * The user is finally requesting the canonical URL of the resource
>> * mod_autoindex works correctly. Since it doesn't emit the path in the link, it would point to the wrong path.
>> * DirectoryIndex will be evaluated only for directories requested with trailing slash.
>> * Relative URL references inside html pages will work correctly.

HL> what are you doing?
I would like apache to serve index.html when users access the
directory, with or without the trailing slash. e.g. /hello or /hello/

HL> You can disable Phusion Passenger for specific URIs with


<Location> blocks and PassengerEnabled off.

Just disable passenger for my RailsBaseURI "/hello"? Wouldn't that
disable my application all together?

> E-mail: i...@phusion.nl

Hongli Lai

unread,
Jan 3, 2010, 10:17:34 AM1/3/10
to phusion-passenger
On Mon, Dec 28, 2009 at 6:44 PM, Ariel <ar...@arielvalentin.com> wrote:
> HL> what are you doing?
> I would like apache to serve index.html when users access the
> directory, with or without the trailing slash. e.g. /hello or /hello/

I think your best bet right now is to use mod_rewrite to rewrite
/hello to /hello/.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl

Reply all
Reply to author
Forward
0 new messages