Path for accessing html, css, php etc folders [duplicate]

2

Could someone explain me this system of nives to access folder in the use of languages like html, css and php (../)(.../)(./).?

    
asked by anonymous 15.04.2017 / 20:54

3 answers

7

The ".." (colon) and the "." (dot)

As RFC 3986 :

  • If the path starts with ../ or ./ then they will be removed from the prefix:

    ../a/b/ca/b/c

  • If the path begins with /./ , /../ they will be replaced by /

    /./a/b/c/a/b/c

  • If you end with /. , /./ , /.. will remove /. and /.. :

    /a/b/c/../a/b/c/ and /a/b/c/./a/b/c/

  • If you end with /./ and /../ you will remove an item:

    /a/b/c/..//a/b/

  • If /../ is in the middle it will remove the prefix (similar to explanation 4):

    /a/b/../c//a/c/

  • If ./ is in the middle it will have the same behavior as explanation 2:

    /a/b/./c//a/b/c/

  •   

    Some extra details on Points and accents on URLs with mod_rewrite

    Of course, reading RFC 3986 is a bit difficult, even for those who already have some experience, some of the examples I've done with tests, to summarize the .. would be to go up one level (if it is not in the prefix) and ./ would be to point the location itself.

    Imagine that we have a folder with this structure:

    ./teste.html
    ./pasta
    ├── index.html
    └── ./paginas
        ├── a.html
        └── b.html
    

    If no /pasta/paginas/a.html click the link:

    <a href="../index.html">teste</a>
    

    It will point to /pasta/index.html

    But if the link is:

    <a href="./index.html">teste</a>
    

    Then it will try to search for /pasta/paginas/index.html , which in the example does not exist.

    And if in /pasta/paginas/b.html you have:

    <a href="../a.html">teste</a>
    

    It will look for something like /pasta/a.html , which would be wrong in the example, it should be:

    <a href="./a.html">teste</a>
    

    To stay at the same level as /pasta/paginas/a.html

    If you have a link like /teste.html or /../teste.html or /./teste.html it will look for something in the root defined, in case the example will look something like /a.html for all the mentioned links, because / in prefix moves to the root.

    Of course this all depends on the place as described, the same goes for CSS and even when using include in PHP.

    The "..." (three dots)

    This is not described in the RFC, probably most applications such as HTTP servers and browsers will interpret this as a file or as an inaccessible path in Apache for example it issues a HTTP 403 Forbidden and usually returns something like:

    Forbidden
    
    You don't have permission to access /.../ on this server.
    

    Or not found

        
    15.04.2017 / 22:26
    2

    It is common for Web pages to use relative URLs containing only a partial path and file name.

    In paths relative to the document, we use point-to-point ./ to indicate that a level should be returned.

    Examples:

    1: To move from the dirc directory to the dir directory:

    ../dira/nomeArquivo.ext
    

    2: To move from the dire directory to the dir directory

    ../../nomeArquivo.ext
    

    3: To move from the dire directory to the dirb directory

    ../../dirb/nomeArquivo.ext
    

    ./ same folder.

        
    15.04.2017 / 21:22
    0

    ../ can be read as a folder above.

    Consider this structure:

    dominio.com/html
    dominio.com/images
    

    Imagine that a page in the /html folder needs to access an image of the /image folder.

    If you know the domain, you will do something like

    <img scr="http://www.dominio.com/image/image01.png">
    

    And you'll be happy until you need to use this code on another domain.

    Whether or not to do it:

    <img scr="../image/image01.png">
    

    The page will understand where the image is. And if you want to reuse the code, or change the domain in the future, you can do it without difficulty. And you will be happy forever.

    Note that you can nest folders by repeating the pattern. Thus ../../ means, two folders above, and so on.

    ./ refers to the same folder. In practice, it is redundant and unnecessary.

    .../ do not know. I never saw it.

        
    15.04.2017 / 21:15