ThinkPHP5.0网站上线报错:Multiple ChoicesThe document name you requested (/index/index/index.html) could no

版权声明:本文为博主原创文章,未经博主允许不得转载。QQ527592435 https://blog.csdn.net/cplvfx/article/details/84968664

背景:我的网站部署的是一台虚拟主机

环境: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

猜你喜欢

转载自blog.csdn.net/cplvfx/article/details/84968664