in reply to Perl file names and extensions

Generally, I think it's a good idea for Perl programs (or, indeed, any programs) not to have an extension. Why should your users know or care what language a program is written in.

Your last example wouldn't work without some kind of mod_rewrite magic, but something that I've used successfully in the past is to create directories containing an index.cgi so you can use URLs like:

http://www.domain.com/acme/login/?mode=new
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Perl file names and extensions
by Aristotle (Chancellor) on Aug 03, 2004 at 15:43 UTC
    You don't need mod_rewrite for that. You could use <Files> or <Location> directives; the latter are more flexible but only work in the main httpd.conf, while the former can be dropped into a .htaccess.

    Makeshifts last the longest.

Re^2: Perl file names and extensions
by bradcathey (Prior) on Aug 03, 2004 at 16:57 UTC

    davorg, thanks for this example. I have seen URL's like this, but could not figure out how it worked. However, I'm still not sure of the mechanics.

    I assume that the index.cgi is in the directory "login" in your example, but does the lone "?" fire the cgi without the need of a program name, as in: /login/index.cgi?mode=new. I.e., the "index.cgi" is not needed, right?

    This is the first time I've been exposed to mod_rewrite and have done some Super Searching and found this by Mad Hatter. Would something like this work with your example?

    RewriteEngine on RewriteBase /subDir/ # only redirect if the file requested isn't index.cgi # capture anything else and redirect it to index.cgi RewriteCond %{REQUEST_FILENAME} !^index.cgi RewriteRule ^(.+)/?$ index.cgi?rm=$1 [L]

    Well, I'll try this to see if it works differently or better than my usual .htaccess:

    Options +ExecCGI SetHandler cgi-script

    —Brad
    "Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton
      You are over thinking it. url.tld/foo/bar/, in apache, attempts to open whatever the default page for a folder is. In most installs of apache, url.tld/foo/bar/ resolves to url.tld/foo/bar/index.html However, you can change which file extensions you want the index page to use, for example, change it to .pl or .cgi. Then url.tld/foo/bar/ resolves to url.tld/foo/bar/index.pl and anything after the question mark is passed to that cgi. You'll notice perlmonks does something similar. The default page is index.pl so perlmonks.org resolves to perlmonks.org/index.pl so perlmonks.org?foo=bar resolves to perlmonks.org/index.pl?foo=bar

        Thanks BUU, got it. Tried out with "index.cgi" and worked like a champ. Though it really gets complicated if I'm passing lots of params, because I first have to call index.cgi and pass something that tells which script to run and then all the params related to that script. So, instead of:

        url.tld/foo/bar/login?name=robert&pass=sf67dfs

        I believe I need:

        url.tld/foo/bar/?run=login&name=robert&pass=sf67dfs

        which doesn't get me that much further. I think I'm ready to go back to cgi-bin ;^)


        —Brad
        "Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton