Reputation: 25
RewriteRule ^(.*)_([^]+).htm/([0-9.]+)$ a.php?f=$1&t=$2&amt_from=$3 [NC]
I have form call a.php with 3 parameters. I am able to use the above rewrite rule, and a_b.htm/c does work.
My problem is when the user click a submit button on the form, they still see
a.php?f=$1&t=$2&amt_from=$3
How do I fix that?
Thanks a lot.
Upvotes: 1
Views: 466
Reputation: 145472
You need your form to generate the correct URL. This is only doable with some Javascript, but basically works like this:
<form action="a.php" method="GET" onsubmit="rewrite_form(event);">
<input name=f value=123>
<input name=t value=ABCABC>
<input name=amt_from value=XYZXYZXYZ>
<input type=submit>
<script type="text/javascript">
function rewrite_form(e) {
var form = document.forms[0]; // .getElementById("form1");
window.location = '' + form.f.value + '_' + form.t.value + '.htm/' + form.amt_from.value;
if (e && e.preventDefault) { e.preventDefault(); }
return false;
}
</script>
So basically the form submit generates the nicer URL you want. If the browser doesn't support Javascript, it will fall back to the more elaborate GET-parameterized URL.
Le Update: The form element access was incorrect, you just need document.forms[0].fieldname.value
usually. And I've moved the URL construction out into a separate function. The onsubmit=
method works well enough with event.preventDefault();
in Opera/Chrome/Firefox.
Upvotes: 1
Reputation: 146302
That is because you are still submitting with a method="get"
, so the form creates that form of url..
Use post instead if you dont want the user to see the submitted values in the url
Upvotes: 0