dongzhan9100 2015-12-14 10:58
浏览 67

Yii从NGINX上的url中删除index.php

I've moved Yii 1 website to a new Ubuntu server with NGINX and all works fine except cleaned URLs without index.php part. For example page http://****/site/about redirects to homepage but http://****/index.php/site/about shows correct page. My current server block configuration file contains this location rules:

location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param QUERY_STRING    $query_string;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
}

I've also tried using

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

but it end up with redirect loop.

Seems like rewrite /index.php$uri?$args never validates against $uri check.

In Yii config I have

'urlManager' => array (
            'urlFormat' => 'path',
            'showScriptName' => false,
            'caseSensitive' => false,
            'rules' => array (
                '<public_url:about>'=>'site/about',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                ....

So the question is how to make http://****/site/about show same page as http://****/index.php/site/about request?

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • duan0708676887 2015-12-14 11:28
    关注

    Seems like rewrite /index.php$uri?$args never validates against $uri check.

    No. The location \.php$ only matches URIs which end with .php. After you append path info, it no longer matches.

    The correct way to process php scripts with path info, is to replace the terminating $ with (/|$) and use the fastcgi_split_path_info directive to separate the path info from the script path name. See this document for details.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog