我的服务器中具有以下文件结构:
/
source/ # source PHP files (not accessible)
public/ # publicly accessible files (media)
.htaccess # second level htaccess to rewrite path into variable
index.php # request collector
.htaccess # first level htaccess to redirect flow into public dir
在htaccess的第一级中,我已重写规则,将流程移到“公共”目录中。
RewriteRule ^(?!public/).*$ public/$0 [L,NC]
“ public / .htaccess”包含以下代码:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !index.php
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
因此,如果请求现有文件,则将其提供。否则,请求将像“ example.com/namespace/controller/action?var=blah”一样重写为“ example.com/index.php/namespace/controller/action?var=blah”
该请求应由“ public / index.php”处理。但是,似乎不允许多次重写。我对吗?也许我做错了什么。我不得不承认我听不懂mod_rewrite。