我在Apache的PHP站点上启用了URL重写( http://example.com/ index.php?param = 12 成为 http://example.com/index/param/ 12 )。

我有一些GET而不是POST的表格。

在对表单进行子搜索后,不会重写生成的URL。

提交GET表单后是否可以保留重写的URL?

更新:我发现这篇文章的主题是 http://matthewjamestaylor.com/blog/how-to-post-forms-to-clean-rewritten-urls 但我真的不喜欢重定向到重写URL的想法。在没有重定向的情况下,真的没有办法保留重写的URL吗?

更新2:这是我正在尝试做的一个例子。 假设我有一个这样的简单形式:

<form method="get" action="">
   <fieldset>
      <input type="text" name="q" />
      <input type="submit" value="Search" />
   </fieldset>
</form>

让我们说我的网址是 http://example.com/index/param/12

提交GET表单后,网址将变为 http:// example.com/index/param/12?q=my-input-text ,虽然我想获得一个重写的网址,如 http://example.com/index/param/12/q/my-input-text

有帮助吗?

解决方案

好像你希望你的表单直接转到 / q / my-input-text ,你应该使用JavaScript在表单的 onSubmit 上实现。

其他提示

apache mod_rewrite只处理传入(请求)网址 - 它无法控制您在PHP脚本中生成的网址。这是你应该照顾好自己的事情。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top