/ in URL
'/' at the end of URL
open nickroh.vercel.app and copy the url from your browser
the result will be
https://nickroh.vercel.app/
not
https://nickroh.vercel.app
Why there is '/' at the end of the URL? It is questionable since both https://nickroh.vercel.app/ and https://nickroh.vercel.app is working.
Trailing Slash
The '/' at the end of URL is called Trailing Slash. Its role is to identify the URL is directory. So if there is trailing slash it is directory if not it is file.
https://nickroh.vercel.app/dir/ # directory
https://nickroh.vercel.app/a.html # file
What if '/' is not used for directory and used for file
The answer is it does not matter for directory and matters for file.
-
Case '/' is missing if '/' is missing in directory url the server treat it as path to file at first. The server searches for the file and if the file doesn't exist the server treat it as a directory
-
Case '/' exists if '/' the server consider it as path to directory, if it it directory eveything is fine but is it was file it will cause error such as 404 not found
How about the domain URL
Actually our browser automatically add trailing slash if it is missed in domain URL
This is specification of URL
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
As we can see not putting trailing slash after domain URL is not identifying path.
Therefore not putting '/' at the end of domain is not identifying the resouce is file or dir. It didn't specified the path to the resource. Therefore out broswer automatically changes
https://nickroh.vercel.app # to
https://nickroh.vercel.app/ # this