问题
I'm creating a php front-controller because I need to include file from other folders instead of creating the same file for those that have the same content
Example of a directory structure
[root]
- start.php
[rome]
- index.php
[subfolder]
- page.php
[london]
(no file)
Here contents of the file
index.php
require '../start.php';
start.php
require 'subfolder/page.php';
And rome/index.php show page.php correctly...
Now in london folder, these are htaccess / front-controller
.htaccess
RewriteEngine On
RewriteRule . front-controller.php [L]
front-controller.php
$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
if (! file_exists ($path) ) include str_replace("london" , "rome" , $path );
When I call london/index.php, response is
Warning: require(subfolder/page.php): failed to open stream: No such file or directory in ...
Fatal error: require(): Failed opening required 'subfolder/page.php'
来源:https://stackoverflow.com/questions/41970755/php-front-controller-to-include-file-from-other-folder-if-not-exist