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

后端 未结 8 1303
梦如初夏
梦如初夏 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:37

    This is a reason many large applications will try to set a 'root URI' constant/variable when installing.

    While /css/style.css will work if your application is located in the root directory of the domain/subdomain, it will fail if it isn't (/appName/css/style.css)

    Store the absolute URI to the 'root' script folder along with other configuration constants/variables, and building absolute links becomes a breeze.

    define( 'SCRIPT_ROOT', 'http://localhost/yourApplication' );
    // ...
    echo '';
    

提交回复
热议问题