problem rewrite form (post)

New to mod_rewrite? This is a good place to start.

problem rewrite form (post)

Postby lusbal » Mon Oct 19, 2009 5:12 am

Hi friends:
Please i need a help. I AM CHANGING MY DINAMIC URL TO FRIENDLY URL AND REDIRECT MY OLD DINAMIC TO THIS NEW STATIC PAGE.

###i have in .htaccess:

RewriteCond %{HTTP_HOST} ^perubookstore.home$ [OR]
RewriteCond %{HTTP_HOST} ^www.perubookstore.home$
RewriteRule ^/?$ /cgi-bin/perubookstore/store.cgi [L]
(store.cgi is my dinamic home page)

####then, to make this old dinamic to static page permanent:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /cgi-bin/perubookstore/store\.cgi\ HTTP/
RewriteRule ^cgi-bin/perubookstore/store\.cgi$ /? [L,R=301]

## this work, but when i use in html for example:

<form method=post action=/cgi-bin/perubookstore/store.cgi>
<input type=hidden name=action value=buy>
<input type=hidden name=quantity value=1>
<input type=hidden name=productid value=PROD2>
</form>

##the rewrite redirect this form to start page and not to cgi-bin/perubookstore/store.cgi?action=buy

NOTE: /cgi-bin/perubookstore/store.cgi (no action, is to start page).

COULD HELP ME?
lusbal
 
Posts: 4
Joined: Mon Oct 19, 2009 4:52 am

Postby richardk » Mon Oct 19, 2009 11:17 am

You need to change
Code: Select all
<form method=post action=/cgi-bin/perubookstore/store.cgi>

to
Code: Select all
<form method="post" action="/">


Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^cgi-bin/perubookstore/store\.cgi$ /? [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?perubookstore\.home$
RewriteRule ^$ /cgi-bin/perubookstore/store.cgi [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks

Postby lusbal » Mon Oct 19, 2009 6:52 pm

thanks so much! one question: what is the difference between {ENV:REDIRECT_STATUS} and {THE_REQUEST} ?
lusbal
 
Posts: 4
Joined: Mon Oct 19, 2009 4:52 am

Postby richardk » Tue Oct 20, 2009 9:18 am

REDIRECT_STATUS is a variable set after a rewrite has happened. It is set to a HTTP status code. By checking it is empty we know a rewrite hasn't happened (ie. the second rule) and a loop won't occur.

THE_REQUEST is the first line from the HTTP request. By matching it you can also not match internal sub requests because it will not change during/after a rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 6 guests

cron