TP5隐藏public和index.php

13 篇文章 0 订阅
8 篇文章 0 订阅

个人理解:
将public下的index.php文件移动到主目录下和更改index的入口文件可以在URL去掉public

将public下的.htaccess文件复制到主目录下并更改配置是:当url地址访问不存在的文件或路径时,调用正则表达式进行替换自动补齐/index.php/。也就是说即使你加上index.php访问也不会出错。

一、Apache
1、public下的index.php入口文件和.htaccess配置文件移到TP5主目录下
在这里插入图片描述
2、修改index.php文件
在这里插入图片描述

https://www.kancloud.cn/manual/thinkphp5/125729
3、修改.htaccess文件

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On
 
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

效果图:
在这里插入图片描述
二、nginx
1、将public下的index.php入口文件移动到主目录下
2、同Apache

3.1、将nginx的nginx.conf服务器配置文件加入以下代码

location /youdomain/ {
if (!-e $request_filename){
        rewrite  ^/youdomain/(.*)$  /youdomain/index.php?s=/$1  last;
    }
}

3.2、如果应用装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

location /youdomain/ {
if (!-e $request_filename){
        rewrite  ^/youdomain/(.*)$  /youdomain/index.php?s=/$1  last;
    }
}

效果图:加不加index.php效果是一样的

在这里插入图片描述
在这里插入图片描述
参考:https://www.fujieace.com/thinkphp/pathinfo.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值