簡體   English   中英

在URL中省略index.php時,總是在Slim Framework中出現404錯誤

[英]Always get 404 error in Slim Framework when omitting index.php in URL

我按照這里的說明創建了一個測試hello world Slim應用程序。

當我撥打這個電話時,我收到404錯誤:

http://my_server/my_app/hello/John

另一方面,當我撥打這個電話時,它會很有效,因為我收到了“Hello John”消息:

http://my_server/my_app/index.php/hello/John

但是,當然,我不想在我的網址中使用index.php ......有什么不對的?

=======編輯=======

我忘了像這樣創建.htaccess文件(在Slim Framework文檔之后,和index.php在同一目錄中):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

現在我收到這個錯誤:

/physical_path_to_my_files/index.php was not found on this server

如果您的htaccess文件位於/my_app目錄中,請將規則更改為:

RewriteEngine On

RewriteBase /my_app/

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

如果它在您的文檔根目錄中,則需要附加路徑:

RewriteRule ^ /my_app/index.php [QSA,L]

也可以將.htaccess更改為以下內容:(我有類似的問題,這解決了我的問題):

的.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

如果Jon Lin解決方案不起作用,則表示您的.htaccess文件無效。 你可以驗證我添加了垃圾線之類的

RewriteEngine On
RewriteBase /loop/v1/

This is garbage line

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

如果.htaccess工作正常,這將產生503錯誤,否則你不會得到任何錯誤。

如果沒有收到任何錯誤,請在apache conf文件或Httpd.conf中更改Allow none to Allow all in section部分

這個資源解釋了我們需要配置以便在Ubuntu上使用slim(它幫助我解決了我的404問題):

總而言之,有兩件事要配置:

  1. 激活mod_rewrite a2enmod rewrite
  2. 修改Apache配置文件(將AllowOverride None更改為文檔根目錄的AllowOverride All

不要忘記在更改后重啟apache2: service apache2 restart

如何在Ubuntu 14.04上安裝和配置Slim Framework

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM