The current directory set up is as follows:
website
- web
index.php
- base
file.php
.htaccess
The document root is the 'web' directory. The index.php file has a require script to get 'file.php'.
require(dirname(dirname(__FILE__)) . '/base/file.php');
What I am trying to achieve is that if the 'base' directory does not exist, the .htaccess file will rewrite the 'base' files to a another location on the local machine. At the moment I have set up an Alias in httpd.conf:
Alias /basefiles "/Users/Guest/base"
<Directory "/Users/Guest/base">
Options +Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and this in the .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule ^base/(.*)$ /basefiles/$1 [L]
At the moment this is not working at all. Anyone any ideas please?
PHP's require
has nothing to do with how files are accessed from the web.
To "rewrite" PHP file locations, you might check explicitly in your PHP script, if the directory and file exists and act accordingly.
Another strategy might set the include_path
( set_include_path
) to something like /.../base:/.../basefiles
and then just
require('file.php');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.