Codeigniter 表单操作使用斜杠而不是普通的 GET?
嘿,这是看起来很明显的问题之一,我可能会觉得很愚蠢,但这里是:
我正在做一个带有搜索的 CodeIgniter 网站。想象一下 Google 类型的输入,您可以在其中搜索“白色哈士奇”。我有一个搜索结果页面,它采用 URI (MySite.com/dogs/white huskies),并采用第三部分,并对该术语执行搜索。我希望在 URI 中完成此操作,而不是通过 POST 完成,以便我的用户可以为结果添加书签。
我遇到的问题是如何将搜索按钮定向到 Mysite.com/dogs/输入内容。如何将输入部分中的内容放入锚点 href 中?我知道我可以用 javascript 做到这一点,但我听说强迫人们使用 javascript 来处理这么小的事情是不好的做法。
感谢您的帮助!
Hey, so this is one of those questions that seems obvious, and I'm probably going to feel stupid, but here goes:
I'm doing a CodeIgniter site with a search. Think of a Google type input, where you'd search for "white huskies." I have a search results page that takes a URI (MySite.com/dogs/white huskies), and takes the third part, and performs the search on that term. I'd like this to be done in the URI, and no by POST so my users can bookmark results.
The problem I'm having is how to get that search button directed to Mysite.com/dogs/WHATEVER IS IN THE INPUT. How do I get the what is in the input part into the anchor href? I know I could do this with javascript, but I've heard it's bad practice to force people to have javascript for things this small.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读:表单重定向到包含查询项的 URL? - 纯 HTML 或 Django
(要求使用 Django,但答案也适合这里)
Read: Form redirect to URL containing query term? - pure HTML or Django
(asked for Django, but answer fits here too)
您可以有一个中间 POST 页面,用于收集表单输入并将它们连接到一个有效的 URL 中,然后您可以重定向到该 URL。然而,我不确定这是好还是坏的 SEO 实践,但我看不到在没有 Javascript 干预的情况下执行此操作的另一种方法。
也许您可以考虑执行中间 POST 页面,该页面将您重定向到 /search/dog/white/huskies,但也有一个 Javascript 等效项,可以在表单提交时动态执行此操作并执行 window.location 刷新到相同的/search/dog/white/huskyes?
只值我的 2 便士;)
You could have an intermediate POST page that collects the form inputs and concatenates them into a valid URL which you can then redirect to. I'm not sure if this is good or bad SEO practice however, but I can't see another way of doing this without some Javascript intervention.
Perhaps you could look at doing the intermediate POST page which takes the values are redirects you to /search/dog/white/huskies, but also have a Javascript equivalent that does this on the fly on the form submit and does a window.location refresh to the same /search/dog/white/huskies?
Just my 2 pennies worth ;)
CodeIgniter 可以安全地处理
$_GET
变量和 URI 段。我过去使用的解决方法是使用 POST 收集搜索词,解析所需的 URL 以与 URI 段一起使用,然后将用户重定向到此页面。
这不会影响 SEO,但搜索结果的 URL 等内容不太可能对 SEO 产生任何影响。干净的 URL 仅适用于永久内容。如果您要在页面上显示搜索词,请记住使用
xss_clean()
,以前见过一些人犯过这个致命错误。It is possible to have CodeIgniter work with
$_GET
variables and URI segments securely.A work around I have used in the past is to have the search term collected using POST, parse the required URL for use with URI segments and then redirect your user to this page.
This shouldn't effect SEO but something like the URL of a search result is unlikely to have any effect on SEO anyway. Clean URLs are only really meant to be used for permanent content. If you're going to be displaying the search term on the page, remember to use
xss_clean()
, seen a few people make this fatal mistake before.