Question

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?

Was it helpful?

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.

OTHER TIPS

For this you can use the base tag.

...
<head>
    <base href="/somepath/">
    ...
</head>
<body>
<!-- the following images src  will be resolved into '/somepath/image.png'
<img src="image.png" alt=""/> 
...    

But then again, why not just use absolute urls, that is, urls beginning with / ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top