in reply to mod_rewrite VS SSI VS your better idea

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.