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

Posted on 2008-11-14
Medium Priority
Last Modified: 2013-11-05
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):
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.

Question by:olevt
LVL 27

Accepted Solution

caterham_www earned 500 total points
ID: 22964104
So you're looking for mod_rewrite?

RewriteEngine on
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:  ^(/[^.]+)$

Author Closing Comment

ID: 31516913
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!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question