9

Is there a difference between these URLs in regards to having slashes at the end of the URL?

https://drchrono.com/about_us
https://drchrono.com/about_us/

Do web frameworks and web servers (e.g. Apache, Nginx, Django) handle these requests differently?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Daniel Kivatinos
  • 24,088
  • 23
  • 61
  • 81

5 Answers5

29

The browser will treat them differently when it comes to relative URLs. A page at:

http://server/path

with a relative link like:

<a href='other'>

will resolve that link to:

http://server/other

replacing path with other. Whereas if the starting URL was:

http://server/path/

then the resolved link would be:

http://server/path/other

If path is a directory rather than a file, most web servers will automatically redirect from:

http://server/path

to:

http://server/path/

because that's almost certainly what you meant.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • 4
    because of that automatic redirect, if you write your links with the trailing slash, you will achieve a minimal but noticeable speedup of your page loads. IIRC, the apache docs recommend this. – rmeador Sep 21 '09 at 22:07
5

In Django URLs without forward slashes automatically have a forward slash appended to them. This is a preference of the Django developers and not a hard-coded rule of the web (I think it's actually a setting in Django).

Kai
  • 9,444
  • 6
  • 46
  • 61
3

/ is the separation character.

From the RFC

Some URL schemes (such as the ftp, http, and file schemes) contain names that can be considered hierarchical; the components of the hierarchy are separated by "/".

Having a / at the end states that there might be more stuff in the url.

Ólafur Waage
  • 68,817
  • 22
  • 142
  • 198
2

Just a side note that search engines view these as 2 different pages. Thus hurting your seo.

corymathews
  • 12,289
  • 14
  • 57
  • 77
1

They are handled as different requests, although they might match the same resource/handler/routine at the end and be processed in the same way.

As the one with / is supposed to be something similar to a directory, all relative links will be inside the / i.e. previous/target/something ... while the one without will have the relative links be at the same level previous/something.

eglasius
  • 35,831
  • 5
  • 65
  • 110