【问题标题】:Nginx and try_flies not working properlyNginx 和 try_files 无法正常工作
【发布时间】:2014-08-19 23:32:57
【问题描述】:

我正在尝试模拟多视图,但我遇到了 try_files 的问题。一切正常,但我想重写所有未管理到 /index.php 的 url(但没有 404):

location ~ ^(/.+)/ {
   try_files $uri $uri/ $1.php?$args @extensionless-php /index.php;
}
location @extensionless-php {
   rewrite ^(.*)/ $1.php;
}

所有 url 都被重写为 /index.php。如果我在第一个位置的末尾删除 /index.php,除了非托管 url(我想重写为索引)之外,一切都很好。任何想法?谢谢

【问题讨论】:

    标签: nginx rewrite multiviews


    【解决方案1】:

    如您所说,您可以尝试从第一个位置删除 /index.php。然后,为了让它在找不到 php 文件时重定向到/index.php,您可以在处理.php 请求的location 中添加几行:

    location ~ \.php$ {
        if (!-f $request_filename) {
            rewrite    .*    /index.php;
        }
        # your other directives such as fastcgi_pass 127.0.0.1:9000; etc.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 2017-11-25
      • 2018-12-12
      • 1970-01-01
      相关资源
      最近更新 更多