Reputation: 81
I have a problem because i can´t work my images or css when my site is like www.site.com/shop
Situation: I have these folders inc img css js
In my root documents i have and in this include i have all the styles.css, scripts and metadata.
So far so good, all the documents work when they are in root document but now i have a new folder called shop where i am putting code to make a store.
mysite/shop
How can i call from the shop/index.php all my images, and css, js and inc ?
I want to avoid using ../img/bla.jpg or ../inc/header.php also because when i include the footer or menu i can´t find the images.
Thanks for all the help.
Upvotes: 0
Views: 1061
Reputation: 349
A direct way to access those from HTML would be to provide the / absolute path that refers to the root of your site ie http://mysite.com/
. For example:
<img src="/img/image.jpg"/>
would point to a folder http://mysite.com/img/image.jpg
no matter what your current url structure is.
There are some (quite common) pitfalls of using this inside server-side PHP to reference files from the root of your site(it will try to read files from the root of your drive on UNIX systems for example) but inside client-side HTML code the absolute root /
works like a charm, getting the right http://mysite.com/
absolute path.
Upvotes: 4
Reputation: 49198
I'm thinking you could use BASE:
<base href="http://mysite.com/shop"/>
Which changes the root path that all of your files will use.
Upvotes: 1
Reputation: 3297
You can also prepend the paths with a forward slash to make them relative to root:
<img src="/somefolder/relative/to/root/image.jpg" />
Upvotes: 2