2016-03-07 144 views
0

快速的问题,我相信有人可以在大约2秒内回答。Laravel子目录根目录不可访问?

我有一个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

尝试写 '字头'=> '/文档' –

+0

感谢,但没有帮助。 – ackerchez

回答

1

这是因为您指向一个存在的目录,所以您的Web服务器不会将请求转发给Laravel的index.php文件。

检查你的apache/nginx配置并寻找重写规则。如果你使用Apache,你可能会发现类似:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 

这意味着,如果该目录(-d)或文件(-f)存在,即改写不会发生。

+0

我已经标记这是正确的,但它是正确的原因是准确的。这是我的更新,以便其他人可以学习。 我试图导航到一个URI,如果“文档”,但因为我也有一个“文档”文件夹在我的公共LARAVEL FOLDER这是导致冲突。本质上,laravel应用程序与apache混淆,因为公用文件夹与URI具有相同的名称。人 - >不要这样做! – ackerchez

1

如果你是在Apache,运行apache2 -v 如果它的Apache 2.4.x的+

  1. 变化

Options Indexes FollowSymLinks MultiViewsOptions +Indexes +FollowSymLinks +MultiViews

  • 变化

    Order allow,deny Allow from all Require all granted

  • 标识它不是2.4.X如果您正在使用nginx的htaccess的

    Options +FollowSymLinks 
    RewriteEngine On 
    
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 
    

    试试这个:

    1. SSH到服务器
    2. sudo nano /etc/nginx/sites-available/default
    3. 修改服务器块看起来像这样

      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; 
      } 
      } 
      
    4. sudo service nginx restart