thinkphp去掉链接上带的index.php
2023-03-29 23:03:03
288
{{single.collect_count}}

thinkphp去掉链接上带的index.php

在用thinkphp链接的时候,它会自动带上入口文件index.php,导致链接变得很难看。 例如:http://localhost/index.php/Home/index/index
不过没关系,我们可以去掉它。

  • Apache
    如果是Apache启动的程序的话,在入口文件(也就是Index.php所在)的同级添加.htaccess文件,内容如下:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

然后就可以去掉Index.php了 如:http://localhost/index.php/Home/index/index

  • Nginx
    如果是Nginx启动的程序的话,在nginx的配置文件nginx.conf中加入一个if判断。
location / {if (!-e $request_filename){ //添加的代码 rewrite ^/(.*)$ /index.php/$1 last;}}
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}