views:

32

answers:

2

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?

+2  A: 
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.

bschaeffer
This looks like a nice way to do what I want. I haven't tried it out yet but I will. Just a note though: regex starts at $1 not $0. Thanks! :)
John Isaacks
Duly noted and corrected.
bschaeffer
A: 

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 / ?

Sean Kinsey