Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML link trailing slash [duplicate]

Tags:

html

The w3schools documentation says:

Without a trailing slash on subfolder addresses, you might generate two requests to the server. Many servers will automatically add a trailing slash to the address, and then create a new request.

It is not clear what exactly this means. What difference does it make to add a trailing slash in the href urls, is there a best practice regarding adding a trailing slash.

like image 692
Tarun Gupta Avatar asked Oct 23 '25 16:10

Tarun Gupta


1 Answers

These are two different URLs:

http://example.com/foo
http://example.com/foo/

Often, but not always, requesting the first URL will trigger the server to reply with a 301 Permanent Redirect to the second URL. The browser will then have to make a second request to the second URL.

This is most commonly the case when the URL is mapped on to a directory on the server's file system and the index.html (or other directory index) is being loaded.

Servers where the content is being dynamically generated (e.g. with an MVC framework like Perl's Catalyst) are less likely to do this. In that case you often have to be even more careful with where you link to because relative URLs will resolve differently from the two URLs.

like image 132
Quentin Avatar answered Oct 26 '25 06:10

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!