简体   繁体   中英

URL rewrite with form and 3 parameters

I have a webpage with a form has 3 parameters, like

http://www.likeforex.com/currency-converter/fxconverter.php?f=euro-eur&t=usd-us-dollar&amt=1

I used .htaccess to rewrite the page to: f_t.htm/amt as:

http://www.likeforex.com/currency-converter/euro-eur_usd-us-dollar.htm/1

However, my question is when user change the value of amt(middle of the page), then the form is re-sumbited, and the re-sumbited page is still in parameter format. How to make the url in after rewrite format?

Anything wrong with the submit button, or anything else?

the form:
<form name="e" method="get" action="fxconverter.php">
the amt parameter:
<input type="text" id="amt" name="amt" size="16" maxlength="16" value="'.$amt.'" onclick="this.focus();this.select();" />'
the submit button:
<input type="submit" value="Convert" class="bt" />
the .htaccess line: 
RewriteRule ^(.*)_([^_]+)\.htm/([^/]+)$ fxconverter.php?f=$1&t=$2&amt=$3 [NC]

Thank you very very much.

You cant use a form, regardless of POST/GET and expect the parameters to output like a url eg http://www.likeforex.com/currency-converter/euro-eur_usd-us-dollar.htm/1

What you need todo is change the form slightly and use javascript to build the url and then redirect.

<script>
function goForm(form){
    f = form.elements["f"].value;
    t = form.elements["t"].value;
    amt = form.elements["amt"].value;

    window.location.href = 'http://www.likeforex.com/currency-converter/'+f+'_'+t+'.htm/'+amt;
}
</script>

<form name="currencyForm" method="GET" action="">
<input id="f" name="f" value="euro-eur" type="hidden">
<input id="t" name="t" value="usd-us-dollar" type="hidden">
<input id="amt" name="amt" size="16" maxlength="16" value="1" onclick="this.focus();this.select();" type="text">
<input type="button" name="button" value="Click" onClick="goForm(this.form)">
</form>

Then you can take advantage of the mod_rewrite.

Tho personally I would scrap the GET (for the fancy url) and just use POST . search engines wont query your form so there is no advantage in using GET only that it may make it easier for someone thinking to scrape your content to digest its workings. Also remember anyone without javascript enabled wont be able to use the form with my solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM