문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top