如何创建搜索,搜索引擎友好(mod_rewrite htaccess)

发布于 2024-09-08 14:19:30 字数 110 浏览 0 评论 0原文

我想知道是否可以创建一个具有操作“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

失去的东西太少 2024-09-15 14:19:30

您无法创建表单来生成所需格式的 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.

国产ˉ祖宗 2024-09-15 14:19:30

您可以将以下代码放入 .htaccess 文件中:

RewriteEngine on
RewriteRule ^/search/(.*)$ /search.php?what=$1

You can put the following code in your .htaccess file:

RewriteEngine on
RewriteRule ^/search/(.*)$ /search.php?what=$1
因为看清所以看轻 2024-09-15 14:19:30

我发现了一种方法来做我想做的事。

<form action="search.php" method="GET" id="form23" name="form23">
<input type=text id=what name=what />
<input type=button value="go" OnClick="document.location='cauta/'+document.form23.what.value;" />
</form>

但请记住,这只是为了人们的浏览体验。

I discovered a way to do what I wanted to do.

<form action="search.php" method="GET" id="form23" name="form23">
<input type=text id=what name=what />
<input type=button value="go" OnClick="document.location='cauta/'+document.form23.what.value;" />
</form>

But remember this is only for people's browsing experience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文