这是我的目录:
root/
├── app/
├── public/
| ├── css/
| ├── img/
| ├── index.php
| ├── .htaccess
├── .htaccess
我希望对文件夹的每个请求都root/被重写到public/文件夹,然后通过变量传递index.phpurl $_GET。
这是我的root/.htaccess:
DirectorySlash off
RewriteEngine on
RewriteRule (.*) public/$1
这是我的root/public/.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
没有RewriteCond %{REQUEST_FILENAME} !-d,因为我不希望用户看到目录,例如:root/css.
当我去root/app它工作正常,我得到$_GET['url'] = 'app'。但是当我去时,root/public我没有得到$_GET['url'] = public;相反,它向我显示了public文件夹的目录结构。当我去root/public/(注意尾部斜杠)时,它会带我去root/public/index.php并且它也不会传递变量。
如果你能告诉我如何解决这个问题,我将不胜感激。我想root/public重写为root/public/index.php?url=public.
编辑:当我去root/public/css它返回$_GET['url'] = 'css'而不是$_GET['url'] = 'public/css'. 似乎在public访问该文件夹时,它忽略了第一个.htaccess文件。