Reputation: 1276
I came across an HTML anchor which reads <a href="\">Home</a>
.
Normally we put something like <a href="index.php">Home</a>
but when I click on <a href="\">Home</a>
I am able to go to the index page on the website.
I can't replicate the behavior on localhost.
Why does \
direct to the website's homepage, and was it intentional on the developer's part?
Upvotes: 1
Views: 2075
Reputation: 5173
You are correct that it is incorrect, and it's almost certainly not intentional. Backslashes (\
) are considered unsafe in URLs, and if a backslash is necessary in your URL you would normally have to encode it as %5C
.
As Rocket Hazmat pointed out in a comment on your question, most browsers automatically substitute /
for \
in URLs.
So the link to \
is converted to /
, which requests the root of the current server. The server is probably set up to serve some default file like index.php
when it receives a request for a directory, and the result is loading the homepage.
I don't know your local http server setup, but chances are it hasn't been configured to serve a specific page (like index.php
) when it receives a request for a directory. So you are likely just seeing a directory listing of whatever is at the root of the local http server you are running locally.
Upvotes: 2