Codeigniter 表单操作使用斜杠而不是普通的 GET?

发布于 2024-08-28 13:47:51 字数 382 浏览 2 评论 0原文

嘿,这是看起来很明显的问题之一,我可能会觉得很愚蠢,但这里是:

我正在做一个带有搜索的 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 技术交流群。

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

发布评论

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

评论(3

尴尬癌患者 2024-09-04 13:47:51

阅读:表单重定向到包含查询项的 URL? - 纯 HTML 或 Django

(要求使用 Django,但答案也适合这里)

Read: Form redirect to URL containing query term? - pure HTML or Django

(asked for Django, but answer fits here too)

只是我以为 2024-09-04 13:47:51

您可以有一个中间 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 ;)

丑疤怪 2024-09-04 13:47:51

CodeIgniter 可以安全地处理 $_GET 变量和 URI 段。

我过去使用的解决方法是使用 POST 收集搜索词,解析所需的 URL 以与 URI 段一起使用,然后将用户重定向到此页面。

$url = 'mysite.com/search/' . urlencode($_POST['query']);

redirect($url);

这不会影响 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.

$url = 'mysite.com/search/' . urlencode($_POST['query']);

redirect($url);

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.

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