nginx 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 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式