The short question is - what is the best practice - to use or not to use a trailing slash in URLs.
There are many articles: this, this, this.
However, they all seem to deal with static directory structure. What about dynamic urls, like those rewritten, or those handled by a central facility (like a web framework, for example), that forward to internal resources depending on convention/configuration. For them it is no longer the case that the web server actually searches and figures out exact locations - it is just a matter of parsing.
So, for example with spring mvc you declare that a given class method is invoked when the URI matches /service/action/{pathParam}
- for this URL, imo, it does not make sense to have a trailing slash - the request is handled by one and the same servlet each time, which does the parsing.
What I think is that one should just be consistent - either use trailing slashes everywhere, or don't use them at all.
So:
If your site has a directory structure, it's more conventional to use a trailing slash with your directory URLs (for example, example.com/directory/ rather than example.com/directory ), but you can choose whichever you like. Be consistent with the preferred version. Use it in your internal links.
When using APPEND_SLASH , if they accidently sent it without trailing slash, and your urlconf is WITH a trailing slash they would get an exception about data lose when redirecting POST requests.
A trailing slash at the end of a URL on your website can cause issues with duplicate content if not dealt with correctly. Put simply, Google doesn't like seeing the same content on different pages. It can be confusing for both search engines and users.
The addition of a slash at the end of a URL instructs the web server to search for a directory. This speeds the web page loading because the server will retrieve the content of the web page without wasting time searching for the file.
in a perfect world people would just copy&paste an URL when they want to link to your stuff. sadly we do not live in a perfect world. people (i.e. pr guys, marketing) tend to typewrite URLs (don't ask me why, they just do....) and then again tend to forget the trailing slash at the end.
the wrong URLs in external links error rate is lower if you don't have trailing slashes.
but for most sites, it does not matter. choose one, stick with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With