Thanks, Mewsham, for the input. After experimenting ( and even going to #httpd on freenode for help ) with mod_rewrite, and it not working*, I tried a ScriptAliasMatch directive in the virtual host file, and it seemed to do the trick.

ScriptAliasMatch ^/foo/(\w+)$ /var/www/foo/cgi-bin/$1.cgi

* When using the SSI method, 'get' arguments would work, but 'post' didn't seem to, although it might have been a different problem. The best I could get out of mod_rewrite was to display the correct script, but not run it.

I'm considering this solved, but if someone else can post the mod_rewrite directive here that they have working in production to accomplish this ( or tell me what I was doing wrong with Mewsham's code ), I'd be happy to give it a try.

Edit/Update: ScriptAliasMatch was working great on my test server, where I have root access, but when beginning to transfer the changes to our productions server, where I do not have root access, I found out that ScriptAliasMatch can only be in server config and virtual host files, and not in .htaccess files. On our production server, all config options must be in .htaccess files, so I went back to Rewrite. I was finally able to make it function properly with the following in my virtual host file:

# the following will redirect www.mysite.com/foo/bar to show the # output of the script previously accessed at # www.mysite.com/foo/cgi-bin/bar.cgi, assuming that direct access to # www.mysite.com/foo/cgi-bin/bar.cgi functions as desired <Directory "/var/www/foo/"> RewriteEngine On # enables Rewrite RewriteBase /foo/ # tells Rewrite to apply the following to # requests beginning with www.mysite.com/foo/ RewriteCond %{REQUEST_URI} !-d # rule applies if request does # not exist as a directory RewriteCond %{REQUEST_URI} !-f # rule applies if request does # not exist as a file RewriteRule ^(\w+)$ /foo/cgi-bin/$1.cgi [L] # perl-compatible # regex applies to # request string # following RewriteBase </Directory>

In the .htaccess file, the Rewrite directives do not need to be in <Directory> tags. If this does not product the expected results, consider changing L for PT at the end of the RewriteRule.

If one has root access to a server, ScriptAliasMatch is a simpler, and, I believe, more efficiently executed directive. If you must use .htaccess files, then Rewrite is your only option. Neither solution affects direct access to www.mysite.com/foo/cgi-bin/bar.cgi.


In reply to Re: mod_rewrite VS SSI VS your better idea by derekstucki
in thread mod_rewrite VS SSI VS your better idea by derekstucki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.