Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rewriting URLs with Perl

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hello,

I would like to know if there's a simple way to rewrite URLs (aka clean URLs)in perl:
from to
I would like to know if it's possible to do this at a script level only meaning I wouldn't have to modify any web server settings.

I'm running Perl on a Win2003 server.

Any input would be really appreciated.

Thanks
 
There's something you can do that's sorta like that...


or the syntax goes "whatever.cgi/any-data-you-want-here", so it looks like a URL path except there's a file extension in there.

The data after the / can be retrieved with $ENV{PATH_INFO}. For example:

(if env.cgi is a simple script that dumps out %ENV):
env.cgi/helloworld/1234/5678
$ENV{PATH_INFO} = "/helloworld/1234/5678"

That's likely the closest you can get without changing the server configuration. If this was an Apache server you could use mod_rewrite in a .htaccess file that you control so you don't need to bug your sysadmins and this kinda stuff would be real easy:

Code:
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /script.pl [L]
</IfModule>

and then script.pl would be able to get $ENV{REQUEST_URI} to find the path actually requested of the server.

If you're running on an IIS server though, I'm not sure right offhand how IIS does things, or if they have a .htaccess-like system that lets sites override server directives themselves. But you didn't specify IIS or Apache, so if it's Apache we're in luck. :)

-------------
Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top