skip to Main Content

Testing in Incognito / Chrome (to force non caching of files I wish to change / develop), the following keeps happening so I was hoping someone could please tell me why:

A php file is referencing and external file in path ‘../../../style.css’ – the file is verified as read.

The path in the php file is CHANGED to: ‘./style.css’; then to: ‘../../style.css’ and no matter how many variations on number of sub-folders it is STILL read.

Non caching has been verified by changing the actual filename to:’styles.css (added s on the end) and the file read fails with a resulting unstyled page.

Can someone please point out why changing the number of sub-folders appears to have NO effect.

Many thanks
Will

Many tests in a non-caching environment.

2

Answers


  1. Chosen as BEST ANSWER

    I was locating the css file relative to the location of the file 'calling' it...

    Back to sub-folder, sub-folder, sub-folder then up into folder 'css'.

    ../../../css/

    It appears the path needs to be relative to the root, NOT the file containing the path.

    Simply /css

    This was discovered by experimenting with what member @deEr suggested (many thanks @deEr)


  2. It is hard to determine the root cause of the problem without seeing the actual code.

    Likely, you have discovered that any relative reference to a file above the root will be resolved to the root itself.

    If for example, we have these files below, the text will be blue. Note that both files are located directly in the root, but index.html references style.css two levels above it.

    /index.html

    <link rel="stylesheet" href="../../style.css" />
    <div>Look at me, I am blue!</div>
    

    /style.css

    div {
      color: blue;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search