0

具体 5 搜索结果页面 url 包含一些参数。如何删除该参数并使 url 用户友好

4

2 回答 2

0

Short answer: it's probably not worth the trouble.

Long answer... I'm guessing you see three query parameters when using the search block:

  1. query
  2. search_paths[]
  3. submit

The first parameter is required to make the searches work, but the other two can be dropped. When I build concrete5 themes, I usually "hard-code" the html for the search form, so that I can control which parameters are sent (basically, don't provide a "name" to the submit button, and don't include a "search_paths" hidden field).

The "query" parameter, though, is not going to be easy to get rid of. The problem is that for a search, you're supposed to have a parameter like that in the URL. You could work around this by using javascript -- when the search form is submitted, use some jquery to rewrite the request so it puts that parameter at the end of the URL (for example, http://example.com/search?query=test becomes http://example.com/search/test). Then, as @tuxtimo suggests, you add a rewrite rule to your .htaccess file to take that last piece of the URL and treat it as the ?query parameter that the system expects. But this won't work if the user doesn't have javascript enabled (and hence probably not for Googlebot either, which means that this won't really serve you any SEO purpose -- which I further imagine is the real reason you're asking this question to begin with).

Also, you will run into a lot of trouble if you ever add another page under the page that you show the search results on (because you have the rewrite rule that treats everything after the top-level search page path as a search parameter -- so you can never actually reach an address that exists below that path).

So I'd just make a nice clean search form that only sends the ?query parameter and leave it at that -- I don't think those are really that much less user-friendly than /search-term would be.

于 2012-08-09T19:40:12.487 回答
0

在 apache 服务器上,我建议您使用 mod_rewrite 模块来使用 RewriteEngine。使用此模块,您可以为某些内部 URL 指定别名(当然也可以使用参数)。您也可以为此使用 RegEx。

维基百科上的重写引擎

mod_rewrite 教程

于 2012-08-08T06:00:15.557 回答