nginx thinkphp 总是返回首页

更新日期: 2019-09-17 阅读次数: 4060 字数: 164 分类: thinkphp

例如,访问

http://localhost/solution.html

总是指向网站首页,但是修改成

http://localhost/?s=solution

这个链接格式之后,就是正常的。

说明这个符合 thinkphp 的 redirect url 模式。

可能需要在 nginx 中对链接进行格式转换。

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        }

修改之后,访问网站的各个页面就正常了。

注:

  • -f 和 !-f 用来判断是否存在文件
  • -d 和 !-d 用来判断是否存在目录
  • -e 和 !-e 用来判断是否存在文件或目录

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式