如何在PHP中将动态文本附加到url?

时间:2014-05-03 13:10:23

标签: javascript php jquery url url-rewriting

我有一个html表单,方法类型是post,现在我想在PHP中将文本附加到我的网站url。文本动态变化。

当前网址:

www.example.com/index.php

预期网址:

www.example.com/index.php/hotels-in-bangalore 

(或)

www.example.com/index.php?qry=hotels-in-bangalore

我只想附加文字,除此之外,每件事都要保持一致。谢谢。

2 个答案:

答案 0 :(得分:1)

我不确定你为什么试图完成,但这里有一些解决方案:

将url置于表单操作中:

<form action="index.php?qry=hotels-in-bangalore" method="post">

或者你可以在php

中完成
if (!empty($_POST['name']) {//put some logic here
  header("Location: index.php?qry=hotels-in-bangalore");
  exit;
}

答案 1 :(得分:0)

如果您想在立即提交后重定向到正确的页面,则需要使用JavaScript。

所以它会是这样的:

<form>
  <input type="text" name="tbSearch" id="tbSearch" />
  <input type="submit" id="submitSearch" value="Submit" />
</form>

<script type="text/javascript">
$("#submitSearch").click(function() {
   window.location.href="index.php?qry=" + encodeURIComponent($("#tbSearch").val());
});
</script>