• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

How to funnel all site URLs through a single CGI script?

I'm writi2ng a web application and need all POSTs and GETs to the site to be passed to a single Perl script. I'll be running it on Apache, so I'm really looking for what to add to and/or change in the httpd.conf file.

Sample URLs would include (note the non-extension names):
http://www.xyz.com/
http://www.xyz.com/public/home
http://www.xyz.com/private/dashboard
and I'd like to have the extra paths beyond .com to be passed to the script.

I've been scouring several books and trying different snippets, but now I've really confused myself.

Thanks!
0
olevt
Asked:
olevt
1 Solution
 
caterham_wwwCommented:
So you're looking for mod_rewrite?

http.conf:
RewriteEngine on
RewriteCopnd %{REQUEST_METHOD} ^(GET|POST)$
RewriteRule ^(/.*)$ /path/to/perl.pl?q=$1 [PT,NS]

That should rewrite any request, except internal subrequests, to your perl script. The QueryString q=... should contain the URL-path.

If you'd like to exclude files (images etc.), the easiest way would be to modify the regular expression so that it doesn't match against URL-paths containing a period:  ^(/[^.]+)$
0
 
olevtAuthor Commented:
Thanks, caterham!

By the looks of it, your suggestion appears to be exactly what I need. And your tip about image files was like reading my mind about the future!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now