如何使用htaccess做这样的事情?
if (is_file($_SERVER['DOCUMENT_ROOT'].'/my_dir'.$_SERVER['REQUEST_URI']))
{
// send file $_SERVER['DOCUMENT_ROOT'].'/my_dir'.$_SERVER['REQUEST_URI']
}
else
{
// forward to front-end controller
}
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
# load /my_dir/<file> if exists
RewriteCond %{DOCUMENT_ROOT}/my_dir/$1 -f [NC]
RewriteRule ^(.*)$ /my_dir/$1.php [L]
# otherwise use front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]