kjd*_*n84 2 php apache .htaccess mod-rewrite
我最近将我的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>
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题。它只是生成空页面,我仍然可以直接访问根目录等中的文件。感谢任何帮助。
您现有的指令专门避免重写现有文件的请求,因此它仍然可以让您访问根目录中的文件。它还会将静态资源重写为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]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1552 次 |
| 最近记录: |