Preventing trailing slash on domain name

前端 未结 4 1572
一整个雨季
一整个雨季 2021-01-19 07:48

I want my site to show up as www.mysite.com, not www.mysite.com/

Does Apache add a trailing slash after a domain name by default, o

相关标签:
4条回答
  • 2021-01-19 08:28

    http://www.searchenginejournal.com/linking-issues-why-a-trailing-slash-in-the-url-does-matter/13021/

    http://www.alistapart.com/articles/slashforward/

    URLs were initially used to model directories, so the trailing slash was required. I think if you don't have the trailing slash some webservers will not be able to find the content correctly.

    0 讨论(0)
  • 2021-01-19 08:30

    As explained by Anthony's first link, the slash is part of the address. Every domain (and not just "the vast majority") has a name resembling www.mysite.com, but this is just a domain name, not an URL. An URL is the address of a file, ie protocol+domainname+pathfile, so http://www.mysite.com/ is added the missing filename by DirectoryIndex and therefore is an URL, but http://www.mysite.com just doesn't mean anything since in this case the file path would be empty. The fact that your browser doesn't display the boring parts of your URL is not related to your website's configuration.

    If really the same browser behaves differently on different websites, I would be curious to know what browser and what websites you used.

    0 讨论(0)
  • 2021-01-19 08:31

    Browser adds such slash automatically when requesting the URL. How it displaying in address bar it's a different story.

    For example: www.adobe.com -- type it in different browsers and see how they will display it:

    • Firefox (Windows, 6.0.2) = http://www.adobe.com/
    • Google Chrome (Windows, 13.0.782.220 m) = www.adobe.com
    • Opera (Windows 11.51) = www.adobe.com
    • Internet Explorer 9 = http://www.adobe.com/
    0 讨论(0)
  • 2021-01-19 08:41

    If you request:

    http://myhost.com

    The request needs to look like this in HTTP:

    GET / HTTP/1.0
    Host: myhost.com

    For historical reasons, some browsers did append the slash because otherwise it translates to

    GET <nothing> HTTP/1.0
    Host: myhost.com

    Which would be an illegal request.

    Note that:

    http://myhost.com/page

    is legal, because it translates to:

    GET /page HTTP/1.0
    Host: myhost.com

    0 讨论(0)
提交回复
热议问题