【问题标题】:nginx rewrite file.php to page.php?page=filenginx 将 file.php 重写为 page.php?page=file
【发布时间】:2011-10-20 18:43:21
【问题描述】:

我对 nginx 很陌生,想设置一个重写,但对我来说总是失败。我想要的是将file.php 重写为page.php?page=file,但我只希望在file.php 不存在时发生。谁能帮我解决这个问题?

我自己尝试了一些重写,但没有任何效果......

【问题讨论】:

    标签: nginx rewrite


    【解决方案1】:

    我现在没有设置 PHP,但这应该可以。

    location /rewrite-test/
    {
        root /var/www/my-website/;
    
        try_files $uri /rewrite-test/page.php?page=$uri;
    }
    

    您可以启用日志记录以查看失败的地方,以防万一它不起作用。

    server
    {
        listen 80;
    
        error_log /var/www/my-website/logs/error.log;
    
        location /
        {
            ....
        }
    }
    

    然后使用这个命令:

    tail -f /var/www/my-website/logs/error.log
    

    【讨论】:

      【解决方案2】:

      我得到了它的工作:

      location ~ (.*/)([\w\-\.]+)\.php {
          try_files $uri $1page.php?page=$2$args;
          include fastcgi_params;
          fastcgi_pass 127.0.0.1:9000;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-06-29
        • 1970-01-01
        • 2016-01-27
        • 1970-01-01
        • 2010-10-03
        • 2015-12-22
        • 2013-03-31
        • 2023-04-04
        • 2012-01-31
        相关资源
        最近更新 更多