我的搜索表单如何提交到不带 的 URL?在中间?
我想创建一个搜索表单。
当我输入查询并按提交按钮时,我想提交到 URL - domain.com/query/there_is_my_query
,但如何实现呢?
如果我将方法更改为 GET,则该 URL 将是 domain.com/query/?query=there_is_my_query
。
但是,如果我将操作更改为 /query/
,然后在控制器中输入 $_POST['search']
,该 URL 将是 domain.com/query
代码>.
编辑!
我思考并决定保留以下网址 - domain.com/query/?search=there_is_my_query
。
I want to create a search form.
When I enter my query and press the submit button, I want submit to a URL - domain.com/query/there_is_my_query
, but how to make this?
If I change method to GET, that URL will be domain.com/query/?query=there_is_my_query
.
But if I change action to /query/
, then In controller put $_POST['search']
, that URL will be domain.com/query
.
Edit!
I thought and decided to leave the following url - domain.com/query/?search=there_is_my_query
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
让您知道,搜索引擎不使用搜索表单。
因此,让它们对搜索引擎友好是没有意义的。
To let you know, search engines do not use search forms.
So there is no point in making them search engine friendly.
您可以修改您的
index.php
以通过重定向重定向任何包含$_GET['query']
的请求,如下所示:或者您需要使用 JavaScript 来创建新的用户单击提交按钮后的 URL。如果你问我的话,这两种解决方案似乎都不太合理。
You can either modify your
index.php
to redirect any request containing$_GET['query']
via redirect like this:Or otherwise you need to use JavaScript to create the new URL once the user clicks the submit button. Neither solution seems overly reasonable, if you ask me.
以下内容可行,但在 Kohana 中使用全局数组被认为是不好的做法:
问题是 Kohana 的路由系统并非设计用于处理查询字符串。如果您确实需要这样做,那么您必须使用 mod_rewrite 将逻辑从 Kohana 移至 .htaccess 文件中。
The following will work, however it is considered bad practice to use global arrays in Kohana:
The problem is that Kohana's routing system is not designed to work with the query string. If you really need to go this this way, then you'll have to move the logic out of Kohana into the .htaccess file, using mod_rewrite.
您可以使用 Apache
rewrite
模块将请求重定向到某个点(引导程序)。该引导程序将解析 URL 并获取参数。You can use the Apache
rewrite
module for redirect the requests to a point (bootstrap). This bootstrap will parse the URLs and it will get the params.