2016-11-20 71 views
1

下午好,阿帕奇 - 404沒有找到

我在闡述一個項目,並且我已經用ubuntu16.04在virtualbox中安裝了php,mysql,apache2。我在本地工作,我已經安裝了laravel 5.3,我正在運行一個API並創建了一個新的虛擬主機,並放置了DocumentRoot my_folder/publicServerName name_virtual_host。然後我去我的主機文件,並放置一個新的行:127.0.0.1 name_virtual_host。當我把我的瀏覽器http://name_virtual_host,出現laravel頁面看做是應該,但是當我在http://name_virtual_host/api類型,還給:

未找到

所請求的網址/ API在此沒有被發現服務器。

Apache/2.4.18(Ubuntu)服務器在name_virtual_host端口80它用於 顯示JSON。

我的虛擬主機:

<VirtualHost *:80> 
     ServerAdmin [email protected] 
     ServerName name_virtual_host 
     DocumentRoot /var/www/my_folder/public 
     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

,如果我的文件夾裏面我寫的COMAND

PHP工匠服務

,放在網址:

name_virtual_host:8000/api

,這個工程。

我該如何解決這個問題? 我認爲解決方案是創建文件.htaccess,但我應該把這個文件(.htaccess)放在什麼?

謝謝。

回答

1

Laravel should come with a public/.htaccess file它將所有請求重定向到index.phpRewriteRule^index.php [L]部分)。

如果您沒有此文件,請添加它。如果你已經有這個文件,請確保你的apache服務器上已啓用mod_rewrite(並重新啓動它)。

如果沒有它,當您請求/api時,Apache將在您的DocumentRoot中查找名爲api的文件。請求必須發送到index.php,從laravel documentation

公共目錄包含index.php文件,這是所有請求進入應用程序的入口點。

+0

非常感謝,錯過啓用的mod_rewrite。謝謝 – Catarina