问题描述
我有一个提交到搜索页面的表单。我可以在后端处理MOD_REWRITE的东西,但想知道以最好的格式获得搜索结果页面的最佳方法。
I have a form which submits to a search page. I can handle the MOD_REWRITE stuff at the back end but want to know the best way to get the search result page in a nice format in the first place.
最好吗?接收表单提交,然后重定向到更好的URL结构。在以下示例中,用户搜索 blah
。
Is it best to receive the form submission, then redirect to a nicer url structure. In the following example the user searches for blah
.
/search.html?searchterm=blah
哪个重定向到
/search/blah/
或者我可以(我的首选项)在用户点击提交按钮后以某种方式使用javascript(或jQuery)执行此操作?
Or can I (my preferred option) do this using javascript (or jQuery) somehow after the user clicks the submit button?
推荐答案
绝对应该阅读此内容教程:
definitely you should read this tutorial:
基础:
-
mysql_real_escape_string()
搜索字词 - 删除所有非Alpha / Num字符
- 在每个匹配的单词之间放置
+
-
SELECT MATCH AGA INST
||在BOLEAN模式
||LIKE
mysql_real_escape_string()
searched term- remove all non Alpha/Num chars
- place the
+
between each matched word SELECT MATCH AGAINST
||IN BOLEAN MODE
||LIKE
mod_rewrite
RewriteRule ^search/([^/\.]+)$ search.php?q=$1
PS:链接中的 PHP
部分是有点outofdate,所以,例如你应该使用 preg_replace
而不是 ereg_replace
,你也可以避免额外的步骤通过在第一次尝试中完成所有操作来剥离空间;你也可以检查停用词
并按照建议的:foo-bar来优化你的正则表达式
。还有其他事情要考虑,但新手是一个很好的起点。
PS: the PHP
part in the link is a little bit outofdate, so, for example you should use preg_replace
instead of ereg_replace
, and you can also avoid the extra step of stripping spaces by doing it all in the first try; you may also check for stopwords
and refine your regex
as suggested ex.: foo-bar. there are other things to consider but for a novice is a good starting point.
这篇关于不错的搜索网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!