htaccess rewriterule in combination with POST form

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&param2=val2 I'...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-27-2005
Bart van den Burg
 
Posts: n/a
Default htaccess rewriterule in combination with POST form

Hi

I´m currently building a new page, and instead of
http://.../page.pl?param1=val1&param2=val2
I'm using
http://.../page/val1/val2

then in .htaccess:
RewriteEngine On
RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page&param1=$1&param2=$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"?


  #2 (permalink)  
Old 01-27-2005
HansH
 
Posts: n/a
Default Re: htaccess rewriterule in combination with POST form

"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&param2=val2
> I'm using
> http://.../page/val1/val2
> then in .htaccess:
> RewriteEngine On
> RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page&param1=$1&param2=$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


  #3 (permalink)  
Old 01-27-2005
Bart van den Burg
 
Posts: n/a
Default Re: htaccess rewriterule in combination with POST form

"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&param2=val2
> > I'm using
> > http://.../page/val1/val2
> > then in .htaccess:
> > RewriteEngine On
> > RewriteRule ^page/(\d+)/(\d+)$ site.pl?page=page&param1=$1&param2=$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??


  #4 (permalink)  
Old 01-27-2005
Bart van den Burg
 
Posts: n/a
Default Re: htaccess rewriterule in combination with POST form

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


  #5 (permalink)  
Old 01-27-2005
HansH
 
Posts: n/a
Default Re: htaccess rewriterule in combination with POST form

"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


  #6 (permalink)  
Old 01-27-2005
HansH
 
Posts: n/a
Default Re: htaccess rewriterule in combination with POST form

"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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0