Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic URLs - with or without a trailing slash? [closed]

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:

  • what's the best practice - with, without, or whatever-just be consistent
  • what's the reason to choose one over the other
like image 831
Bozho Avatar asked Oct 08 '10 08:10

Bozho


People also ask

Should you include trailing slash in URL?

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.

What happens if you skip the trailing slash?

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.

Do trailing slashes matter for SEO?

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.

What do the slashes mean in a URL?

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.


1 Answers

  • most important: stay consistent - 1 URL == 1 page
  • redirect one (wrong one) to the other (right one) via an HTTP 301 redirect
  • then again if you have a website where different people work with: don't do trailing slashes.

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.

like image 112
Franz Enzenhofer Avatar answered Sep 21 '22 09:09

Franz Enzenhofer