2012-07-14 22 views
0

我有一個形式的網頁,有3個參數,如URL重寫與形式和3個參數

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

我用的.htaccess頁面改寫爲:f_t.htm/amt爲:

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

但是,我的問題是當用戶更改amt(頁面中間)的值時,表單被重新組合,並且重新組合的頁面仍然是參數格式。如何在重寫格式後製作網址?

提交按鈕或其他任何錯誤?

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] 

非常感謝。

+1

你能告訴我們表格和相關的mod_rewrite,否則它是一個猜謎遊戲...... – 2012-07-14 16:18:06

+0

沒什麼。只有RewriteRule ^(。*)_([^ _] +).htm /([^ /] +)$ fxconverter.php?f = $ 1&t = $ 2&amt = $ 3 [NC] – 2012-07-14 16:22:50

+0

@ likeforex.com請更新你的問題。 – Gumbo 2012-07-14 16:26:42

回答

1

你不能使用的一種形式,無論POST/GET並期望參數輸出就像一個網址如http://www.likeforex.com/currency-converter/euro-eur_usd-us-dollar.htm/1

你需要待辦事項什麼是稍微改變形式和使用JavaScript來構建URL,然後重定向。

<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> 

然後你可以利用mod_rewrite。

我個人會棄GET(對於花哨的url),只是使用POST。搜索引擎不會查詢你的表單,所以在使用GET時沒有任何優勢,因爲它可以讓那些想要抓取你的內容來消化其工作的人更容易。還記得任何沒有啓用JavaScript的人將無法使用我的解決方案的形式。

+0

非常感謝。沒有其他解決方案沒有JS? – 2012-07-14 17:22:49