1. 程式人生 > >ThinkPHP5.0網站上線報錯:Multiple ChoicesThe document name you requested (/index/index/index.html) could no

ThinkPHP5.0網站上線報錯:Multiple ChoicesThe document name you requested (/index/index/index.html) could no

背景:我的網站部署的是一臺虛擬主機

環境:Apache

程式:ThinkPHP5.0

資料庫:mysql

必須項:開啟偽靜態

 

域名解析,原始碼線上部署後:開啟網站提示:

 

Multiple Choices

The document name you requested (/index/index/) could not be found on this server. However, we found documents with names similar to the one you requested.

Available documents:

/index.php/index/ (common basename)

 

/index/index/login/logout.html

這個直接訪問是不能訪問的

/index.php/index/login/logout.html

在第一個輸入 .php才可以正常訪問

 

解決:

通過詢問後才知道是什麼原因造成的,在這裡特別感謝 qq暱稱為“獨門絕技”大神協助

搜尋關鍵詞為:tp5隱藏入口檔案index.php

網上的答案:(我嘗試失敗)

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
  RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>
 

“獨門絕技”大神的答案 (我嘗試正確)

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
#RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
#RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

大神這裡是把?號給去掉了

tip:"#"是註釋掉這行程式碼

 

延伸閱讀:

摘自:https://www.cnblogs.com/xiaozong/p/5782291.html

.htaccess重寫URL講解

使用ThinkPHP和Laravel等框架的都知道,所以的請求都需要經過index.php檔案入口,無論你的URI是什麼。

當然除了訪問的是靜態檔案或者訪問路徑的檔案真實存在,例如你訪問xxx.com/home/page.html

首先,web伺服器先去更目錄找home資料夾下面的page.html,如果存在就訪問這個檔案,如果不存在就重新URL,進入index.php大入口

當然,這一切都是規則制定的。請看下面的.htaccess檔案【不記得怎麼寫我教你,.ht+access 】

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

RewriteCond的 %{REQUEST_FILENAME} !-d 的意思是訪問的路徑不是一個目錄時RewriteRule才能生效

RewriteCond的 %{REQUEST_FILENAME} !-f  的意思是訪問的路徑不是一個檔案時RewriteRule才能生效

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 的意思是將訪問路徑重寫到index.php/的後面,最為引數傳遞給index.php檔案

 

詳細的RewriteCond的規則請看這篇博文:http://blog.sina.com.cn/s/blog_545759110100h5g4.html

詳細的RewriteRule的規則請看這篇博文:http://blog.csdn.net/paulluo0739/article/details/17711851