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

本文详细介绍了在Apache环境下,ThinkPHP5.0框架如何正确配置伪静态规则,以实现URL美观且无需显示入口文件index.php。通过对比不同.htaccess配置,解决了访问网站时出现MultipleChoices错误的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橙-极纪元JJYCheng

客官,1分钱也是爱,给个赏钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值