<form> action not being relative


This is a pretty basic question 😀

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>
  • 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


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.

Answered By – Teckstudio

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.