venturemob has asked for the wisdom of the Perl Monks concerning the following question:

I've run into an issue with Mod Rewrite when submitting forms to our site perl scripts. If someone does a GET request on a page with a url such as http://www.site.com/us/florida/page-title I rewrite that using the following rewrite rule which works correctly:

RewriteRule ^us/(.*)/(.*)$ /cgi-bin/script.pl?action=Display&state=$1& +page=$2 [NC,L,QSA]

Now if that page had a form on it I'd like to do a form post to the same url and have Mod Rewrite use the same rewrite rule to call the same script and invoke the same action. However, what's happening is that the rewrite rule is being triggered, the correct script is being called and all form POST variables are being posted, however, the rewritten parameters (action, state & page in this example) aren't being passed to the perl script. I'm requesting these variables using the same perl code for both the GET and POST requests:

use CGI; $query = new CGI; $action = $query->param('action'); $state = $query->param('state'); $page = $query->param('page');

I included the QSA flag since I figured that might resolve the issue but it didn't. If I do a POST directly to the script URL then everything works correctly. I'd appreciate any help in figuring out why this isn't currently working. Thanks in advance!

Replies are listed 'Best First'.
Re: Mod Rewrite Issues on Form Post in Perl
by Fletch (Bishop) on Oct 16, 2009 at 14:35 UTC

    Look for the section on "MIXING POST AND URL PARAMETERS" in the CGI docs; URL parameters are ignored by param for a POST (but still available via url_param).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Mod Rewrite Issues on Form Post in Perl
by derby (Abbot) on Oct 16, 2009 at 18:04 UTC

    You probably have /cgi-bin ScriptAliased, so you'll need the PT flag to mod_rewrite (and there's probably no need for QSA).

    -derby