我最近将我index.php
(处理路由的文件)和css / js / font资产移到了public/
文件夹中。public/
为了安全起见,我只希望访问此文件夹中的项目。当我意识到我可以mysite.com/composer.lock
使用旧的.htaccess
文件夹设置访问并查看作曲家锁定文件时遇到了这个问题。
这就是我想要的
如果我访问mysite.com/car/create
,我希望它实际指向mysite.com/public/index.php?path=car/create
如果我链接到资产,例如mysite.com/css/style.css
,我希望它真正指向mysite.com/public/css/style.css
这是我的文件夹结构
这是我.htaccess
根本不工作的
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ public/index.php?path=$1 [L,QSA]
</IfModule>
我不确定如何解决此问题。它只是生成空白页,我仍然可以直接访问根目录等中的文件。我们将提供任何帮助。
您现有的指令特别避免了重写现有文件的请求,因此它仍然使您能够访问根目录中的文件。还将静态资源重写为public/index.php?path=
,这可能会失败。
请尝试以下操作:
RewriteEngine On
# Stop processing if already in the /public directory
RewriteRule ^public/ - [L]
# Static resources if they exist
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
# Route all other requests
RewriteRule (.*) public/index.php?path=$1 [L,QSA]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句