如何创建搜索,搜索引擎友好(mod_rewrite htaccess)
我想知道是否可以创建一个具有操作“search.php?what=bla bla”的 GET 表单,并在网址栏中显示“search/bla bla”。然后我可以处理搜索文件并分解搜索词,但是重写规则是什么?
I want to know if it's possible to create a GET form that has as action "search.php?what=bla bla" and in the url bar it shows "search/bla bla" . Then I can handle the search file and explode the search terms, but what is the rewrite rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法创建表单来生成所需格式的 URL,并且它对搜索引擎没有任何用处。
但是,例如,当列出“最近搜索”时,您可以以
search/bla%20bla
格式列出 URL,并使用 Patrick 给出的重写规则。顺便说一句,请务必小心您的输入验证。
You can't create the form to generate the URL in the desired format, and it's not of any use search engine wise.
However, when for example listing 'recent searches', you can list the URLs in the format
search/bla%20bla
, and use the rewrite rule given by Patrick.Be very careful with your input validation BTW.
您可以将以下代码放入 .htaccess 文件中:
You can put the following code in your .htaccess file:
我发现了一种方法来做我想做的事。
但请记住,这只是为了人们的浏览体验。
I discovered a way to do what I wanted to do.
But remember this is only for people's browsing experience.