1

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 Answers 2

3
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.

Sign up to request clarification or add additional context in comments.

1 Comment

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! :)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.