Using Apache to fix your application solves it at the wrong level.
If you need to update a bunch of files in your code when the file location is changed, this is your code telling you that you made a poor architectural decision. Therefore, correct the actual problem and stop repeating.
Determine where your included people live in one place, and then, when necessary, update this place accordingly.
One way to do this is to set a constant in the root of your application. This assumes that you have some code at the root of your application that is invoked on every page. Most likely this is index.php or the script included by index.php :
// index.php or a file included by index.php const MY_INCLUDE_PATH = __DIR__ . '/path/to/subfolder'
Then your other scripts can call include using constant:
// some other script included to handle the page include MY_INCLUDE_PATH . '/config.php'; include MY_INCLUDE_PATH . '/some-other-include.php';
Although if everyone wants to include the config.php , maybe just include it in your index.php .
This is not a "bad" world that you want to avoid. It uses constants as they are intended. Constants are part of the namespace if you use the namespace for your application.
This assumes that there is one subfolder that sometimes changes places and the script somewhere that is part of each request. It's right? If not, submit your directory structure.
The function will also work and may include logic based on things like the path of the calling script:
// index.php or a file included by index.php my_include_function($path) { //do stuff }
Other scripts may call this function as follows:
Then, when the situation changes, you simply update one function in one file.
All this assumes that you have index.php or a similar script that processes each request and may be the only control point for defining a function or constant. If it is not, then it must be!
Updating the code to use the router ( here it is ) will take about 10 minutes and may simplify this gnarly.htaccess file that you published.