快速提问,我相信有人可以在大约2秒内回答。
我已经设置了一个Laravel项目,并且其中一个子目录已设置为文档。
我已设置以下代码。
Route::group(['prefix' => 'docs'], function(){
route::get('/', function(){
return redirect('docs.intro');
});
Route::get('/intro', ['as' => 'docs.intro', function(){ return view('docs.intro'); }]);
});
当我导航到" www.site.com/docs/intro"一切正常。但是,当我导航到" www.site.com/docs /"它没有像我希望的那样重定向,而是抛出一个403"禁止"错误。有人知道为什么吗?我怎样才能正常工作?
谢谢!
答案 0 :(得分:1)
这是因为您指向了存在的目录,因此您的网络服务器不会将请求转发给Laravel的index.php
文件。
检查您的apache / nginx配置并查找重写规则。如果你正在使用apache,你可能会发现类似的东西:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
这意味着如果目录(-d
)或文件(-f
)存在,则重写不会发生。
答案 1 :(得分:1)
如果您使用的是apache,请运行apache2 -v
如果是Apache 2.4.x +
Options Indexes FollowSymLinks MultiViews
至Options +Indexes +FollowSymLinks +MultiViews
更改
Order allow,deny
Allow from all
来
Require all granted
我不是2.4.X在htaccess中尝试这个
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
如果您使用的是nginx:
sudo nano /etc/nginx/sites-available/default
将服务器块修改为如下所示
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public; **//Modify this according to your project**
index index.php index.html index.htm;
server_name server_domain_or_IP; **//Modify**
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo service nginx restart