我正在尝试重定向到文件的子目录,但如果该文件存在于子目录中,则仅。基本上,它的模型如下:
艰难的部分已经迈出了第2步。这是我尝试过的目标:
RewriteEngine On
RewriteCond engine/%{SCRIPT_FILENAME} -f [OR]
RewriteCond engine/%{REQUEST_FILENAME} -d
RewriteBase /lab
RewriteRule ^(.*)$ /lab/engine/$1 [P]
答案 0 :(得分:3)
# check if the file exists
# ...and if found, stop and display it
RewriteCond %{DOCUMENT_ROOT}/engine/%{SCRIPT_FILENAME} -f
RewriteRule ^(.*)$ /engine/$1 [L,QSA]
# second try to find its in another directory
# ...and if found, stop and display it
RewriteCond %{DOCUMENT_ROOT}/lab/%{SCRIPT_FILENAME} -f
RewriteRule ^(.*)$ /lab/$1 [L,QSA]
# default
RewriteRule ^(.*)$ index.php [L,QSA]
答案 1 :(得分:3)
我设法使用稍微不同的方法让它工作。我首先检查文件是否存在于子目录中,否则我将继续使用动态控制器 - 其中包括对真实文件的排除。
DirectoryIndex handle.php RewriteEngine On # # check if the file exists in "engine" # # ...and if found, stop and display it RewriteCond %{DOCUMENT_ROOT}/lab/engine/$1 -f RewriteRule ^(.*)$ /lab/engine/$1 [L,QSA] # If we've gotten here, route to dynamic controller RewriteBase /lab RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ handle.php [L,QSA]