Code前端首页关于Code前端联系我们

如何在Nginx环境下隐藏thinkphp5中的index.php?

terry 2年前 (2023-09-28) 阅读数 56 #未命名

打开Nginx.conf

查找服务器{}:

        location / {
            index  index.html index.htm index.php l.php;
           autoindex  off;
        }

替换为:

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

如果你的ThinkPHP安装在二级目录下,Nginx的伪静态设置方法如下,这里你的域名来自它所在的目录。

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

PS:做完以上配置后,需要将首页访问门指向公共目录,否则不会成功。

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

热门