Re: Perl file names and extensions
by davorg (Chancellor) on Aug 03, 2004 at 15:17 UTC
|
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
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
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
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
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
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Re: Perl file names and extensions
by nite_man (Deacon) on Aug 03, 2004 at 15:51 UTC
|
Let's see how do it with mod_perl (example from mod_perl documentation):
This is an URL on website -
http://example.com/news/20021031/09/index.html
but you need convert it as
http://example.com/perl/news.pl?date=20021031&id=09&page=index.html
You can use for that simple mod_perl handler:
package MyApache::RewriteURI;
use strict;
use warnings;
use Apache::RequestRec ();
use Apache::Const -compile => qw(DECLINED);
sub handler {
my $r = shift;
my($date, $id, $page) = $r->uri =~ m|^/news/(\d+)/(\d+)/(.*)|;
$r->uri("/perl/news.pl");
$r->args("date=$date&id=$id&page=$page");
return Apache::DECLINED;
}
1;
Also, you should add in http.conf:
PerlTransHandler +MyApache::RewriteURI
So, first URL is easier to understand for user than second. Also, based on this you can create something like selector to process and redirect HTTP requests according your rules.
---
Schiller
It's only my opinion and it doesn't have pretensions of absoluteness!
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Perl file names and extensions
by lhoward (Vicar) on Aug 03, 2004 at 15:24 UTC
|
If you have control of your webserver, there are tricks you can play there too. on apache I have one server set up to handle .html files as if they were php (so nobody knows I use php) and mod_rewrite to obfuscate filename extensions and CGI parameters (and the fact that its even a cgi-bin script). i.e. mapping /foo/bar/login to /cgi-bin/login.cgi?a=foo&b=bar
L | [reply] [Watch: Dir/Any] |
|
Ah... I see! But I only have limited control over my webserver, that's what I get for being a cheapskate...
| [reply] [Watch: Dir/Any] |
Re: Perl file names and extensions
by pelagic (Priest) on Aug 03, 2004 at 15:29 UTC
|
If your webserver knows what to do whith it, it must be ok. For me the only reason to use suffixes as .pl .pm etc. is for humans beeing able to distinguish the probable file use from its name. But I actually prefer other ways e.g. directories. Working in unix systems you anyway can't rely on the suffix only.
There is a caveat with require; see require.
| [reply] [Watch: Dir/Any] |
Re: Perl file names and extensions
by katgirl (Hermit) on Aug 03, 2004 at 15:24 UTC
|
How would this actually work? Perhaps it's just me, but that url would give a 500 error, which I would then have to capture using another script and redirect to the proper url... is there Another Way To Do It? | [reply] [Watch: Dir/Any] |
|
No no not all - it just depends on the configuration of the webserver, of course if you are on windows which depends on the extension to know what to do with the file then you are a bit stuck, short of some ISAPI filter magic or creating some completely different extension, but with , say Apache, this is common practice - of course if you are using mod_perl the thing in the 'file' position at the end of the url may not actually be a physical resource at all.
/J\
| [reply] [Watch: Dir/Any] |
|
Yeah. Use mod_rewrite.
--
< http://www.dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
| [reply] [Watch: Dir/Any] |