2016-10-20 31 views
1

如何提交表單方法getmod_rewrite網址是什麼?如何使用mod_rewrite url提交表單方法get?

這是我的代碼

<form method="GET" action="https://www.example.com/search/"> 
    <input type="text" name="search" value="" placeholder="search"> 
    <input type="submit" value="OK"> 
</form> 

當我提交表單。這是將被重定向到

https://www.example.com/search/?search=test 

我如何能將我的代碼重定向到

https://www.example.com/search/test/1 

提交表格後?

+0

_method 1_:使用'POST',而不是'GET'; _Method 2_:使用javascript/jquery提交表單,在那裏你可以從表單元素構建你的url – Thamilan

回答

0

後端應該設置Location頭:

Location: https://your.domain/search/test/1 

The code

$ cat search/index.html 
<form method="GET" action="https://your.domain/search/post.php"> 
    <input type="text" name="search" value="" placeholder="search"> 
    <input type="submit" value="OK"> 
</form> 


$ cat search/post.php 
<?php 
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: https://your.domain/search/test.html"); 
    exit(); 
?> 

$ cat search/test.html 
Redirection works fine 

要動態決定重定向到哪裏,你應該檢查$POST[ ]哈希值。

+0

我必須申請關於我的表單代碼? –

+0

是的,你另外應該檢查你是否沒有'POST/GET'數據顯示你的表單其他重定向。 –

+0

我不明白你能給我一些示例代碼嗎? –