Benua
Benua

Reputation: 269

Loading same assets from different folders using one header and footer

So I have a webpage where I use the same header/footer for every page:

<?php include 'header.php?>

In header link to css looks like this:

<link rel="stylesheet" type="text/css" href="styles.css">

they both are in the same folder.

Problem:

When I try to load page in another folder (products/page.php) - the assets wont load properly. I put a link to header like this:

<?php include '../header.php' ?>

header and footer loads properly but the assets defined in them do not.

How can I fix the paths so I would not need to copy same files to every folder.

Sorry for noob question :)

Upvotes: 0

Views: 125

Answers (1)

Philipp Gebert
Philipp Gebert

Reputation: 131

A pssible solution is to use absolute paths:

<link rel="stylesheet" type="text/css" href="/styles.css">

This way your assets are indepent to your phps structure.

Upvotes: 2

Related Questions