Reputation:
As I'm developing my website, I also do some small projects that I would put into my website. I'd like to have my project section that link to my project. I want each project to have it's own CSS file so that I don't have one that would be very huge. So here's my problem, I have some issue finding the right path to link my css.
Since I use PHP, I have a public folder with the main index.php used as a simple router. Here's my architecture :
|img\
|-- some images
|public\ (docroot)
|--index.php
|--js\
|----index.js
|--style\
|----partials\
|-------_projet.scss
|----main.scss (with @import 'partials/projet')
|----main.css
|templates\
|--projet\
|----files for the project
|--all my templates like header.php, footer.php...
Here's index.php in public/ :
<?php
require "../vendor/autoload.php";
$required = null;
$projet = null;
$title = 'KumaTeK';
$uri = $_SERVER['REQUEST_URI'];
switch($uri) {
case '/' :
$required = '../templates/home.php';
break;
case '/projets/projet1' :
$projet = '../templates/projet1/index.php';
$title = 'Projet1';
break;
default :
$required = '../templates/404.php';
break;
}
if ($required) {
require '../templates/header.php';
require $required;
require '../templates/footer.php';
}
?>
In my header.php I have :
<link rel="stylesheet" href="style/main.css">
Which works on home.php (or '/' for the route). But when I go to /projets/projet1, I have the HTML without CSS.
I'd like to know if there is a technique to find the correct path or if I'm doing something wrong. (I have also an issue with path for images.)
Upvotes: 1
Views: 1619
Reputation: 76
As it's written in comment you must write :
<link rel="stylesheet" href="/style/main.css">
Which is different that
<link rel="stylesheet" href="style/main.css">
In the first case, the url will be always relative to your domain name, that means that even if your url is http://localhost/projets/projet1
, the css url will be http://localhost/style/main.css
(it's not relative to your current url).
In the second case, the css url will be relative to your current url, that means that even if your url is http://localhost/projets/projet1
, the css url will be http://localhost/projets/projet1/style/main.css
(it's relative to your current url).
Upvotes: 0