< form>行动不是相对的

发布于 2025-02-03 12:43:31 字数 512 浏览 2 评论 0原文

这是一个非常基本的问题:D

我在localhost/book上有一个html,其中具有

    <form action="d" method="get">
      <input name="q" placeholder="Book name"></br>
      <button type="submit">Search</button>
    </form>
  • 与当前URL相对的d动作,

    d动作,哪个localhost/book,对吗? ,因此单击搜索应该像localhost/book/d?q =某些+数据

  • 相反,但是,它就像localhost/d?q = some+data+data

  • 我如何使其转到localhost/book/d

This is a pretty basic question :D

I have an HTML at localhost/book which has a form,

    <form action="d" method="get">
      <input name="q" placeholder="Book name"></br>
      <button type="submit">Search</button>
    </form>
  • The d action meant to be relative to current URL, which localhost/book, right?
    , so clicking Search should go like localhost/book/d?q=some+data

  • But instead, it goes like localhost/d?q=some+data.

  • How do I make it goes to localhost/book/d

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

攒一口袋星星 2025-02-10 12:43:31

这是一个URL问题:因为您的当前URL缺少尾随的斜杠(/),所以URL的最后一部分不被视为文件夹,而是“文件”。因此,如果您提交表格,则在您的情况下将继续升级。

一种解决方案是在URL中添加后斜线。这可以通过在网络服务器级别上重写来完成。或者,您可以更改链接,但是在这种情况下,如果访问者正在键入斜线,则永远不会安全。

更安全的解决方案将不在形式的作用中使用相对URL。

This is a URL-Issue: Because your current URL is lacking a trailing slash (/) the last part of the URL is not treated as a folder but a "file" instead. So if you submit the form it will go on level up in your case.

One solution would be to add a trailing slash in the URL. This could be done by rewrite on web-server level. Or you could change the link, but in that case you are never safe if the visitor is typing a slash or not.

The safer solution would be not to use a relative URL in the action of the form.

末が日狂欢 2025-02-10 12:43:31

有关与父目录相关的,请使用

action =“ ../ D”

For being relative to parent directory, please use

action = "../d"

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