This is a discussion on htaccess rewriterule in combination with POST form within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi I´m currently building a new page, and instead of http://.../page.pl?param1=val1¶m2=val2 I'...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi
I´m currently building a new page, and instead of http://.../page.pl?param1=val1¶m2=val2 I'm using http://.../page/val1/val2 then in .htaccess: RewriteEngine On RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page¶m1=$1¶m2=$2 This works perfectly fine. in my script i can access the parameters using the param() function. The problem however is, when i have a form like this: <form action="page/val1/val2" method="post"> <input type="text" name="param3" value="val3"/> <input type="submit" value="go!"/> </form> i can't access param1 and param2 from my script anymore! Long story for a short question: What can I do, so that i can access those parameters again, but still making the form method="post"? |
|
|||
|
"Bart van den Burg" <bart@NOSPAM.tvreclames.nl> schreef in bericht
news:ctbq5j$2rc$1@reader10.wxs.nl... > I´m currently building a new page, and instead of > http://.../page.pl?param1=val1¶m2=val2 > I'm using > http://.../page/val1/val2 > then in .htaccess: > RewriteEngine On > RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page¶m1=$1¶m2=$2 I'ld like to add the [QSA] flag to this line, IIRC otherwise using from-methode GET would loose param3=val3. > This works perfectly fine. in my script i can access the parameters using > the param() function. > The problem however is, when i have a form like this: > <form action="page/val1/val2" method="post"> > <input type="text" name="param3" value="val3"/> > <input type="submit" value="go!"/> > </form> > i can't access param1 and param2 from my script anymore! > Long story for a short question: What can I do, so that i can access those > parameters again, but still making the form method="post"? It's common for many scripts|script-languages to not-listen to the querystring -the '?...&....&...' part- when the request is POSTed. Most languages will be able to read the PATHINFO -the '/val1/val2' part directly -need to set a directive to allow usage under Apache2-. Should not be too hard to split and URLdecode the lot, making the rewrite obsolete too. HansH |
|
|||
|
"HansH" <hans@niet.op.het.net> schreef in bericht
news:41f97506$0$23751$e4fe514c@news.xs4all.nl... > "Bart van den Burg" <bart@NOSPAM.tvreclames.nl> schreef in bericht > news:ctbq5j$2rc$1@reader10.wxs.nl... > > I´m currently building a new page, and instead of > > http://.../page.pl?param1=val1¶m2=val2 > > I'm using > > http://.../page/val1/val2 > > then in .htaccess: > > RewriteEngine On > > RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page¶m1=$1¶m2=$2 > I'ld like to add the [QSA] flag to this line, IIRC otherwise using > from-methode GET would loose param3=val3. > > > This works perfectly fine. in my script i can access the parameters using > > the param() function. > > The problem however is, when i have a form like this: > > <form action="page/val1/val2" method="post"> > > <input type="text" name="param3" value="val3"/> > > <input type="submit" value="go!"/> > > </form> > > i can't access param1 and param2 from my script anymore! > > Long story for a short question: What can I do, so that i can access those > > parameters again, but still making the form method="post"? > It's common for many scripts|script-languages to not-listen to the > querystring -the '?...&....&...' part- when the request is POSTed. > Most languages will be able to read the PATHINFO -the '/val1/val2' part > directly -need to set a directive to allow usage under Apache2-. > Should not be too hard to split and URLdecode the lot, making the rewrite > obsolete too. Hi It's indeed possible for me to read the PATHINFO. But i thought it looked better with .htaccess :) Alright, I'll do it that way then! Thanks! Bart p.s. What is a [QSA] flag?? |
|
|||
|
if interested to know, i did it like this now:
our $basedir = "/TVR%20new/"; my $req = $ENV{REQUEST_URI}; $req =~ s/^$basedir(.*)/$1/; my ($page, @args) = split(/\//, $1); if ($page) { if ($page eq 'reclames') { use reclames; if ($args[0] =~ /^\d+$/) { $site->param(CONTENT => reclames_show($args[0])); } elsif ($args[0] eq "vote") { $site->param(CONTENT => reclames_vote(param('rid'))); } } } in .htacces: RewriteEngine On RewriteRule ^$ site.pl RewriteRule ^reclames site.pl Bart |
|
|||
|
"Bart van den Burg" <bart@NOSPAM.tvreclames.nl> schreef in bericht
news:ctbsve$qvv$1@reader10.wxs.nl... > "HansH" <hans@niet.op.het.net> schreef in bericht > news:41f97506$0$23751$e4fe514c@news.xs4all.nl... > It's indeed possible for me to read the PATHINFO. But i thought it looked > better with .htaccess :) Alright, I'll do it that way then! Rewrites in .htaccess, being interpretated on every request, are a performance penalty. If you have to use them, include them in the config file(s). > p.s. What is a [QSA] flag?? Excerpt from http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html 'qsappend|QSA' (query string append) This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule. HansH -- Unfortunately Apache2 comes without a Rich Text Formatted Manual |
|
|||
|
"Bart van den Burg" <bart@NOSPAM.tvreclames.nl> schreef in bericht
news:ctbth0$rat$1@reader10.wxs.nl... > if interested to know, i did it like this now: > > our $basedir = "/TVR%20new/"; > > my $req = $ENV{REQUEST_URI}; > $req =~ s/^$basedir(.*)/$1/; > my ($page, @args) = split(/\//, $1); > > if ($page) { > if ($page eq 'reclames') { > use reclames; > if ($args[0] =~ /^\d+$/) { $site->param(CONTENT => > reclames_show($args[0])); } > elsif ($args[0] eq "vote") { $site->param(CONTENT => > reclames_vote(param('rid'))); } > } > } > Path_info is available seperately too: Make this a script print "content-type: text/html\n\n<UL>"; foreach $key (keys %ENV) { print "<LI><B>$key</B> = <B>$ENV{$key}</B></LI>\n"; } print "<UL>"; and see what comes from Apache to Perl. HansH |