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

Posted on 2008-11-14
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

    So you're looking for mod_rewrite?

    RewriteEngine on
    RewriteCopnd %{REQUEST_METHOD} ^(GET|POST)$
    RewriteRule ^(/.*)$ /path/to/$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

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting ( to http…
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now