1

I am trying to use location.href to a folder where a index.php file is located!

So when I am use location.href = "databases?page=settings"; it redirects me to

/databases/?page=settings. Why is Javascript adding a / before the pathparameter?

1 Answers1

0

That's the way href works, It is designed to change URL to a child page of current page, unless you specify you want to go to another domain (for example having http:// at the start of the url). If you looking to change URL otherwise, you can use location.replace(document.location + "databases?page=settings")

  • "It is designed to change URL to a child page of current page" So why does `location.href = "https://google.com/";` take me to https://google.com/ and not to a child page? Perhaps you should amend your statement... – Heretic Monkey May 27 '21 at 20:35
  • Yeah, sorry. That's because you have specified `https://` at the start of the the string, so it's obvious that you are going to another domain, but for example, `location.href = "google.com/"`; will forward you to `/google.com` – Mohamad Chamanmotlagh May 27 '21 at 20:40
  • I thing its an Webserver Issue. I am using nginx. My main problem is the trailing slash before the pathParam. – Stefan Scharinger Nov 15 '22 at 20:25