Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Trailing slash problem with mod_perl

by jest (Pilgrim)
on Sep 28, 2004 at 15:46 UTC ( #394640=perlquestion: print w/ replies, xml ) Need Help??
jest has asked for the wisdom of the Perl Monks concerning the following question:

This seems like the sort of thing that would be covered in a dozen FAQs, but I can't seem to find it anywhere, and Googling has yielded nothing relevant.

I have an app running under mod_perl, with my own handler. The relevant block in my httpd.conf is:

<Location /foo> SetHandler perl-script PerlHandler FooModule </Location>

When I go to this app at http://localhost/foo/, it works fine, likewise for anything under this, such as http://localhost/foo/action/?id=23, the path-parsing etc. being handled in my app. My only problem is that http://localhost/foo, without the trailing slash, goes nowhere; it doesn't even get to my app.

The only thing I want to do is have the slash-less URI go to the slash-ful URI; I want http://localhost/foo to reach http://localhost/foo/. I don't care about anything underneath, I'm picking that up fine. But I don't know how to do this. All the Alias-type directives seem intended to map URIs to filesystem locations, and I don't have a filesystem location, I have something dynamically generated by my handler.

What's the obvious thing I need to do here?

Thank you.

Comment on Trailing slash problem with mod_perl
Select or Download Code
Re: Trailing slash problem with mod_perl
by Velaki (Chaplain) on Sep 28, 2004 at 16:06 UTC

    This is less of a perl issue, and more of an Apache configuration issue, but one key question is:

    Which version of Apache are you running?

    If it's 2.0, then you might be able to modify your location directive as follows:

    <Location /foo> DirectorySlash Off SetHandler perl-script PerlHandler FooModule </Location>
    This will turn off the mod_dir redirects, even though they should redirect from slashless to slashful (love that word) resources; however, it depends on other configuration directives.

    Also, ensure that ServerName has been set explicitly.

    Hope this helped,
    -v
    "Perl. There is no substitute."
Re: Trailing slash problem with mod_perl
by sgifford (Prior) on Sep 28, 2004 at 16:13 UTC

    This is likely to be an Apache problem. You can probably fix it with a RewriteRule that simply adds a slash:

    RewriteEngine On RewriteRule ^/foo$ /foo/ [R]
    If there might be arguments after foo, adding something like this might work:
    RewriteRule ^/foo[^/](.*)$ /foo/$1 [R]

    These aren't tested, but you get the idea.

•Re: Trailing slash problem with mod_perl
by merlyn (Sage) on Sep 28, 2004 at 16:39 UTC
    I explain how I handled this in my mod_perl Picture Handler column. If your handler gets a directory for a URI that doesn't end in slash, it must decline it unless it's prepared to handle the redirect that mod_dir normally does. In short:
    use Apache::Constants qw(:common DIR_MAGIC_TYPE); ... sub handler { my $r = shift; return DECLINED if $r->content_type eq DIR_MAGIC_TYPE and not $r->uri =~ m{/$}; ... }
    If you don't want to handle directories at all, leave off the latter part of the check: just return DECLINED for anything that is DIR_MAGIC_TYPE.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://394640]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2015-07-06 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls