将心比心,方得人心~

Nginx 环境下怎么隐藏 thinkphp5 入口 index.php?

周洲 2017-07-21 11:33:14

打开Nginx.conf

找到 server {}里的:


        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的伪静态方法设置如下,其中youdomain是所在的目录名称。


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



PS:做以上配置后还需要把首页访问入口指向public目录,否则不会成功。


打赏

『微信打赏』

Tag标签Nginx 隐藏index.php 

我是有底线的