3

The website URL is http://example.com but some pages have been redirected to http://example.com/, the version of the URL with the trailing slash. Should I change all redirects to the non-trailing-slash URL?

Stephen Ostermiller
  • 98,758
  • 18
  • 137
  • 361
Maryam Beheshti
  • 389
  • 2
  • 10
  • Are you talking about the trailing slash on the home page (the root of the domain) without any extra path? The situation for that (http://example.com vs http://example.com/) is different than for a directory (/folder vs /folder/). – Stephen Ostermiller Oct 16 '18 at 12:46
  • Actually it is the homepage not subfolder – Maryam Beheshti Oct 16 '18 at 13:46
  • 1
    Launch some developer tools inside your browser, and inspect the HTTP request being done. Even if you type just a name or an "URL" like http://example.com you will see that your browser sends in fact a GET / request, so at least a / is mandatory to say "root". – Patrick Mevzek Oct 16 '18 at 14:57
  • Yes, as Patrick suggests, don't just look at the "beautified" URL in the browser's address bar. Browser's notoriously "beautify" the public URL seen in the browser - more so these days than they ever did. See also: https://webmasters.stackexchange.com/questions/35643/is-trailing-slash-automagically-added-on-click-of-home-page-url-in-browser – MrWhite Oct 16 '18 at 17:22
  • not really matter for redirect in q if done corecct but redirect technique also matters, for example doing apache redirect without trailing slash will most probably fail if original request came with path like example.com/foo. it will redirect to invalid example.comfoo – Sampo Sarrala Nov 03 '18 at 03:07

1 Answers1

3
  • Homepage: Google has stated that the homepage doesnt really matter if there is or isnt a trailing slash.

  • Directory: directories must have a trailing slash in the end.

  • File/Page: an html page or an file shouldn't have a trailing slash.

John Could
  • 739
  • 5
  • 12
  • 2
    It's not just Google. When it comes to the home page, the HTTP spec states that there is no difference between having a trailing slash and not having one. Whether or not the slash shows in the URL, the HTTP request must include the slash. – Stephen Ostermiller Oct 16 '18 at 14:51
  • Note example.com/index.php are the same as example.com/index.php/something at least for apache. You can process this trailing uri in index.php, making possible to use different urls with same script without mod_rewrite – LeonidMew Oct 18 '18 at 00:52