开发者

Rewriting URI within Nginx

Im trying to get URI Routing set up for my framework and im currently working on nginx as teh server, but the problem is i keep getting 500 error when trying to access either one of the following links

  • http://localhost.framework/
  • http://localhost.framework/index.php/

If I access the site using the following links it works:

  • http://localhost.framework/index.php
  • http://localhost.framework/index.php?/

my configuration for the domain is as follows:

server {
    listen 80;
    server_name localhost.framework;
    root   /var/www/ASFramework;

    access_log  /var/log/nginx/framework.access.log;
    error_log  /var/log/nginx/fr开发者_JAVA百科amework.error.log;

    location / {
        rewrite ^/(.*)$ /index.php/$1 last;
    }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
        include        fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  /var/www/ASFramework$fastcgi_script_name;
        }
}

basically what im trying to do is take the following url

  • http://localhost.framework/controller/method/../

and rewrite it to:

  • http://localhost.framework/index.php/controller/method/../

Within the logs (error.log) is:

2011/07/03 22:57:22 [error] 19837#0: *6 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/", client: 127.0.0.1, server: localhost.framework, request: "GET / HTTP/1.1", host: "localhost.framework"

Can anyone tell me what's going on and how I can fix it?


Change this line:

location ~ \.php$ {

into this:

location ~ \.php.*$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  /var/www/ASFramework$fastcgi_script_name;
}


Your rewrite rule causes redirection cycle. nginx substitutes index.php with index.php/index.php recursively. So after second replacement your new URL will be index.php/index.php/index.php and so on.

You probably want something like this:

location / {
    rewrite ^/index.php\?action=(.*)$ /$1 last;
}

Which rewrites index.php?action=someaction to /someaction.


Try this:

location / {
    if ($request_uri !~ "/(index\.php)") {
        rewrite ^/(.*)$ /index.php/$1 last;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜