2016-03-07 104 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