Rewrite or internal redirection cycle?

Hi,

I’m having a bit of an issue with the rewrite scheme:

server {

location / {
try_files $uri $uri/ @data;
}

location @data {
rewrite ^ /data.php$is_args;
internal;
}

}

When I access this request:
http://domain.com/information/feedback/?order=desc&sort=date

I get an internal redirection cycle:
*1 rewrite or internal redirection cycle while processing “/data.php?”,
client: IP, server: domain.com, request: “GET
/information/feedback/?order=desc&sort=date HTTP/1.1”, host:
domain.com”, referrer: “http://domain.com/information/feedback/

However, if I access this request:
http://domain.com/information/feedback/400028-some-information.html

Everything works properly. What do you recommend to do, in order to
troubleshoot the issue?
My goal is to actually log what goes wrong with the php code, when the
redirection cycle is encountered.

Thanks for your help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,199260,199260#msg-199260

On Thu, May 19, 2011 at 09:20:55AM -0400, TECK wrote:

location @data {
*1 rewrite or internal redirection cycle while processing “/data.php?”,
redirection cycle is encountered.

Thanks for your help.

You should either add “break” to stop internal redirection cycle:

location @data {
rewrite ^ /data.php$args break;
}

or should define /data.php in try_files

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

or (my favorite) should define exactly what nginx should do in @data:

location @data {
fastcgi_pass …
fastcgi_param SCRIPT_FILENAME /path/to/data.php;

}

The later way looks more complex at the first sight, but it creates
independed locations and allows configuration to grow at very large
scale.


Igor S.

Thank you Igor, I will use the SCRIPT_FILENAME setup.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,199260,199596#msg-199596

if is evil. (and not needed)

I get the same problem with TECK
The difference is my homepage is work well, but when I tried to click a
link on my homepage, it’s get me 500 Internal Server Error.

Here my configuration:

if (-f $document_root/maintenance.html) {
rewrite ^(.*)$ /maintenance.html last;
break;
}

location / {
    error_page 404 = //index.php?q=$uri;
    try_files $uri $uri/ /index.php?q=$request_uri;
}

location /administrator/ {
    rewrite  ^(.*)$  https://www.domain.com$1 permanent;
}

if ($request_uri ~* "com_login") {
    rewrite  ^(.*)$  https://www.domain.com$1 permanent;
}

location /en/ {
    index index.php;
    error_page 404 = //index.php?q=$uri;
    if (!-e $request_filename) {
        rewrite ^/en/(.*)$ /en/index.php?$1 last;
        break;
    }
}

location /en/administrator/ {
    rewrite  ^(.*)$  https://www.domain.com$1 permanent;
}

location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME

$document_root$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;

and some output from error_log :

2011/06/15 19:41:54 [error] 1985#0: *208 rewrite or internal redirection
cycle while internal redirect to “//index.php”, client: 66.249.72.65,
server: www.domain.com, request: “GET /agenda.html HTTP/1.0”, upstream:
“fastcgi://127.0.0.1:9000”, host: “www.domain.com
2011/06/15 19:41:55 [error] 1985#0: *213 rewrite or internal redirection
cycle while internal redirect to “//index.php”, client: 203.130.206.49,
server: www.domain.com, request: “GET /diploma.html HTTP/1.0”, upstream:
“fastcgi://127.0.0.1:9000”, host: “www.domain.com”, referrer:
http://www.domain.com/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,199260,207142#msg-207142

On 15 Jun 2011 14h11 WEST, [email protected] wrote:

I get the same problem with TECK The difference is my homepage is
work well, but when I tried to click a link on my homepage, it’s get
me 500 Internal Server Error.

Here my configuration:

Your configuration suffers from a lot of mod_rewrite influenced
thinking. As Igor calls it, it’s a Yoda style of configuration.

This makes no sense. You’re doing a capture that you don’t use and
you seem to be rewriting to the same URI.

if (-f $document_root/maintenance.html) {
rewrite ^(.*)$ /maintenance.html last;
break;
}

location = /maintenance.html { }

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

location /administrator/ {
rewrite ^ https://www.domain.com$request_uri? permanent;
}

location ~* com_login {
rewrite ^ https://www.domain.com$request_uri? permanent

}

location /en/ {

location /en/administrator {
rewrite ^ https://www.domain.com$request_uri? permanent;
}

location /en/(.*)$ {
index index.php;
try_files $uri $uri/ /en/index.php?$1;
}
}

location ~ .php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;

Instead of this insecure config, if the handler script is index.php do:

location = /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}

— appa

On 15 Jun 2011 15h33 WEST, [email protected] wrote:

}

This can be made simpler I believe. Just

location /en/(.*)$ {
index index.php;
try_files $uri $uri/ /en/index.php?$1;
}

should do the trick. Try it.

Also you’ll need to create another location for = /en/index.php.

location = /en/index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}

— appa

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs