How to write the correct path to these files?

I have a PHP file located here:

/public_html/folder1/folder2/index.php 

and this file requires a CSS file located here:

 /public_html/folderX/folderY/css1.css 

What is the correct way to access this CSS file that I have to put in index.php? thanks.

+4
source share
2 answers

Assuming public_html is your root:

 <link rel="stylesheet" type="text/css" href="/folderX/folderY/css1.css" /> 

My personal advice is not to interfere with relative paths; they will only kill you when you start moving PHP scripts; or, even worse, when your code is included as part of another script, and you don't know where it is.

The same can be said for links inside CSS (images); it’s not always immediately obvious that relative paths inside CSS files are taken from the location of this file, unlike inline CSS, which uses page layout.

+5
source

You can add it relative to the document:

../../folderX/folderY/css1.css

Or relative to the document root:

/folderX/folderY/css1.css

+4
source

Source: https://habr.com/ru/post/1441724/


All Articles