Search code examples
phpheaderhyperlinkinclude-path

Include a header in a parent folder and getting problems with links


I'm trying to organize my php-project by puting some files into folders. When I change my include from

include("header.php");

to

include("../header.php");

The link stops working and so does the css-stylesheet. How can I fix this bug, or am I doing something wrong .


Solution

  • Instead of links like:

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

    Or

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

    Make them all relative to the document root (start with /):

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

    Same for links etc.