清洁网址搜索查询? [英] Clean URLs for search query?

查看:258
本文介绍了清洁网址搜索查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本作品:

HTML

<a href="/search/querystring">query</a>

的htaccess

RewriteRule ^search/([-0-9a-z]+)$ /search.php?q=$1 [L]


去通过搜索方式:


Going through a search form:

<form method="get" action="/search">
<input type="search" name="q" value="querystring" />
<input type="submit" />
</form>

  • 结果: http://example.com/search?q=querystring
  • 期望的结果: http://example.com/search/querystring
    • Result: http://example.com/search?q=querystring
    • Desired result: http://example.com/search/querystring
    • 这可能与htaccess的还是需要从内部的search.php重定向用PHP?

      例期望的结果在行动: http://twitter.com/search/hello

      Example desired result in action: http://twitter.com/search/hello

      修改

      我preFER不依赖于JavaScript来做到这一点,以便搜索引擎和乡亲禁用了JavaScript会看到这一点。

      I prefer not to be dependant on JavaScript to do this so search engines and folks with JavaScript disabled will see this too.

      推荐答案

      我认为这个问题是你已经创建了GET方法,它会自动打开这样你指定作为结果的URL的HTML表单。如果你想提交您的搜索查询像所期望的,你应该有一些JavaScript破解表格打电话给你好看的网址是这样的:

      I think the problem is that you've created an HTML form with GET method, which automatically opens the URL that way you specified as the result. If you want to submit your search query like the desired one, you should hack the form with some JavaScript to call your good-looking URL like this:

      <form method="get" action="/search/" onsubmit="return false;">
      <input type="search" name="q" value="querystring" />
      <input type="submit" onclick="window.location.href=this.form.action + this.form.q.value;" />
      </form>
      

      这篇关于清洁网址搜索查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆