SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member
    Join Date
    Oct 2009
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about trailing slash with URL

    On some other forum I recently put link to my portfolio page and at the end of the URL I put trailing slash ( / ) like this

    http://www.domain.com/portfolio.html/

    I did not realize that the above page does not exist on my site because my portfolio page does not have trailing slash.

    http://www.domain.com/portfolio.html

    I just saw 20 NOT FOUND errors in google webmasters tools.

    Isn't there any way to redirect all URLs with / to without slash URLs?
    Last edited by Mittineague; Feb 26, 2011 at 22:22. Reason: removing unnecessary link

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by leopard View Post
    Isn't there any way to redirect all URLs with / to without slash URLs?
    actually, and this is perhaps gonna surprise you, but that trailing slash should actually be there whenever you are linking to a directory

    if you send a request for http://example.com, the web server says "i ain't got a file by that name" so your browser automatically slaps a trailing slash on it and makes a second request for http://example.com/ -- this is a valid folder (the root folder), so you get the default page for that folder

    if you ~do~ have folders in your web site, the same thing happens when you send a request for http://example.com/myfolder -- the web server says "i ain't got a file by that name" so your browser automatically slaps a trailing slash on it and makes a second request for http://example.com/myfolder/ -- and once again, this is a valid folder, so you get the default page for that folder

    does that make sense?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by leopard View Post

    Isn't there any way to redirect all URLs with / to without slash URLs?
    my understanding is that /'s in urls are used to simply separate directory names in the urls just like they are used to separate directories/folders in a path name to a file on your computer.

    if a url ends with a / that is telling the server the last name in the url path is a folder and the server sends back the default page in that folder (usually something like index.php, index.htm, home.php or home.htm

    is telling the server that portfolio.html is a folder when in reality it is not.

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I noticed this issue very late. This site is running as it is for the past 2 years and never got issue, it has got PR4 and now if I do something to put / at the end it can affect my site ranking

    Also, I don't know how to put / at the end. It is simple HTML site, no scripts running (except for order page).

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Some CMSs by default don't add a trailing slash at the end of the url, even though it appears to be a folder.

    Quote Originally Posted by leopard View Post
    I don't know how to put / at the end. It is simple HTML site, no scripts running (except for order page).
    If you put a file into a folder and call the file index.html (or index.php etc—the important bit is "index") then you can point to it by citing just the folder.

    E.g.

    If you put an index.html page inside a folder called /articles/ which is inside the root folder, you can point to that index page like this:

    mysite.com/articles/

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    If you put an index.html page inside a folder called /articles/ which is inside the root folder, you can point to that index page like this:

    mysite.com/articles/
    IF DirectoryIndex is turned on. It is by default on my version of Apache, but I dunno about all other servers.

  7. #7
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by leopard View Post
    Isn't there any way to redirect all URLs with / to without slash URLs?
    That would only work if you include a filename in every URL and don't expect anyone to ever try to visit a URL without including the filename. And that ain't going to happen. Because, as Rudy said, if someone hits on a URL without a filename, but just the domain name and maybe a folder name, the trailing / is automatically added. So if you remove it, that's going to cause problems.

    What I'm sure you could do is redirect any URLs that end .html/ to end .html - you might be better off asking about that on the Apache forum, because I'm none too sure about creating the regular expression to do that...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •