如何使用mod_rewrite url提交表单方法?

时间:2016-10-20 04:42:41

标签: php html forms apache mod-rewrite

如何使用get网址提交表单方法mod_rewrite

这是我的代码

<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

提交表格后?

1 个答案:

答案 0 :(得分: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[ ]哈希。