当我访问localhost/project
时,我得到了这个错误
Forbidden
You don't have permission to access this resource.
Apache/2.4.29 (Ubuntu) Server at localhost Port 80
当我尝试访问项目根目录时,我的index.php
在public
文件夹(project/public/index.php)
中,所以我使用.htaccess
将请求重定向到公用文件夹,但这似乎不起作用我试图设置AllowOverride All
,但没有帮助我试图更改所有项目权限,即使是777
,仍然不起作用
这是我的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
我使用的是ubuntu 18.08-PHP 7.3-Apache
您可以在/project/.htaccess
:中拥有此功能
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^s?]*) [NC]
RewriteRule ^ /project/%1 [L,NE,R=301]
RewriteRule ^(.*)$ public/$1 [L,NC]
那么在project/public/.htaccess
:中有这个规则
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
只需将其放在您的项目文件夹中。htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/.]*)/?$ public/index.php?%{QUERY_STRING} [L]
</IfModule>