【问题标题】:Nginx: HowTo rewrite nonx-existing .php file to index.php?Nginx:如何将不存在的 .php 文件写入 index.php?
【发布时间】:2017-03-29 10:34:36
【问题描述】:

下面你会看到我的服务器部分工作得很好,但现在我必须“模拟”一个不存在的 php 文件。

location ~ \.php$
{ 
 fastcgi_pass php;
 include fastcgi.conf;
}

try_files $uri $uri/ /index.php?$uri&$args;

我的所有 url 当前都被重写了,因为我的 index.php 的 try_files 设置,但如果我尝试访问 domain.tld/something.php 则不会。

我怎样才能使这些位置块/s 使domain.tld/something**.php** 使用我的try_files 并将其发送到index.php

提前致谢。

【问题讨论】:

    标签: php nginx url-rewriting location


    【解决方案1】:

    对我来说工作得很好。希望这对您也有用。

    location ~\.php$ {
        index index.php index.html;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        try_files /index.php /index.php;
    }
    

    【讨论】:

    • 太棒了 ;),只需在 .php 位置中的 try_files 就可以了!谢谢!
    猜你喜欢
    • 2022-08-19
    • 2019-01-28
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 2015-01-26
    • 2015-05-07
    相关资源
    最近更新 更多