admin管理员组文章数量:1633912
由于太久没用使用过php了,在搭建新项目使用tp5的时候直接看的文档的路由模块,结果跳过了一些必要的配置环节导致路由没有生效,踩了一点坑
需要重写url来隐藏应用的入口文件index.php
,下面是相关服务器的配置参考:
[ Apache ]
httpd.conf
配置文件中加载了mod_rewrite.so
模块AllowOverride None
将None
改为All
- 把下面的内容保存为
.htaccess
文件放到应用入口文件的同级目录下
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
注意:若出现No input file specified.提示信息,请将<IfModule></IfModule>标签内最后一行改成如下:
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
[ IIS ]
如果你的服务器环境支持ISAPI_Rewrite
的话,可以配置httpd.ini
文件,添加下面的内容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config
,在中间添加rewrite
节点:
<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
[ Nginx ]
在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf
中配置转发规则实现:
location / { // …..省略部分代码
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
其实内部是转发到了ThinkPHP提供的兼容URL,利用这种方式,可以解决其他不支持PATHINFO的WEB服务器环境。
如果你的应用安装在二级目录,Nginx
的伪静态方法设置如下,其中youdomain
是所在的目录名称。
location /youdomain/ {
if (!-e $request_filename){
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=/$1 last;
}
}
本文标签: 路由
版权声明:本文标题:记录thinkphp5路由失效的一些坑 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729177751a1188932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论