Search code examples
phpjavascriptcssinclude-path

set include_path for embed files like .js and .css?


OK so I now know there is a way to put all my php files in a single place and have them be able to be included without a filepath by setting an include_path like so:

php_value include_path .:/pathToPHPFiles

OK so now as long as my PHP files are in this directory I can include them from any subdirectory as if they were in the same directory.

I am wondering if there is a trick like this for other file types like .css and .js so I can put them all in single location and embed them in a page without worring about the filepath?


Solution

  • define("CSSPATH", "/path/to/css/");
    
    echo '<link rel="stylesheet" type="text/css" href="'.CSSPATH.'style.css" />';
    

    or, in a .htaccess file:

    RewriteEngine on  
    RewriteRule ^(.*\.css)$ path/to/css/$1
    

    I'm not sure about the .htaccess version... corrections welcome.