How can I access the parameters passed in the url when the form is submitted to my script?

I'm having a problem with mod_rewrite when submitting forms to our site perl scripts. If someone makes a GET request on a page with a url, for example http://www.example.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 there was a form on this page, I would like to write the form post to the same url and Mod Rewrite use the same rewrite rule to call the same script and invoke the same action. What happens however is that the rewrite rule is triggered, the correct script and all forms of POST variables are called, however the rewritten parameters (action, state, and page in this example) are not passed to the Perl script. I am accessing these variables using the same Perl code for both GET and POST requests:

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

      

I turned on the QSA flag as I realized that it might solve the problem, but it is not. If I POST directly to the URL script then everything works correctly. I would appreciate any help figuring out why this is not currently working. Thanks in advance!

+2


source to share


2 answers


If you are making a POST request you need to use $query->url_param('action')

etc to get the parameters from the query string. You don't need or need the QSA modifier.



+6


source


Change your script to:

use CGI;
use Data::Dumper;

my $query = CGI->new; # even though I'd rather call the object $cgi
print $query->header('text/plain'), Dumper($query); 

      



and take a look at what is being passed to your script and update your question with this information.

+3


source







All Articles