How to use relative paths for included files such as .css

后端 未结 8 1286
梦如初夏
梦如初夏 2020-12-29 15:07

I have a header.php file which contains a .css file link.

When I \"include\" header.php into another php file in different fo

8条回答
  •  情歌与酒
    2020-12-29 15:42

    Based on Tom's answer I did a combination of base url and a PHP define (for less typing).

    Somewhere in PHP:

    define("HOST_BASE", "http://example.com/");
    

    Then in the header file:

    
    

    The base tag was new to me and I was worried about compatibility, but it appears to work well. There is more info about it at MDN.

提交回复
热议问题