# Rewrite or internal redirection cycle while internally redirecting to "/index.php"

**URL:** <https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle-while-internally-redirecting-to-index-php/225285>\
**Category:** NGINX\
**Created:** [December 27, 2012, 12:35pm UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle-while-internally-redirecting-to-index-php/225285 "2012-12-27T12:35:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [December 27, 2012, 12:35pm UTC](https://www.ruby-forum.com/t/rewrite-or-internal-redirection-cycle-while-internally-redirecting-to-index-php/225285/1 "2012-12-27T12:35:19Z")

</div>

Hello everyone,  
I’m having some issue with X-accel and I’d be happy if someone could  
look  
over my configuration file and let me know what I did wrong.  
I am basically running nginx/1.2.5 with php-fpm 5.3.3 on Centos 5.5

I am running an application that is served using Zend Framework from  
/var/www/domain/html/http  
I have many files available for download from  
/var/www/domain/html/files/projects/$id/$file\_name ($id is anything  
ranging  
from 1-999 and $file\_name is a zip file).

I want to basically serve the zip files using X-Accel and bypass  
php-fpm.

In the application when I check if the file can be served or not - I  
added  
this: header("X-Accel-Redirect: " . $file); in order to serve it using  
X-Accel.

I also added this location in my config to serve the zip files using  
nginx  
location /projects {  
internal;  
root /var/www/domain/html/files;  
}

The problem is I get a 500 error and when I look at the log file - this  
is  
what I can spot:

[error] 10274#0: \*25 rewrite or internal redirection cycle while  
internally  
redirecting to “/index.php”

This is the content of my domain.conf in /conf.d

server {  
listen 80;  
listen 443 ssl;  
server\_name [domain.com](http://domain.com);  
ssl\_certificate /etc/nginx/certs/www.domain.com.crt;  
ssl\_certificate\_key /etc/nginx/certs/www.domain.com.key;  
return 301 $scheme://www.domain.com$request\_uri;  
}  
server {  
listen 80;  
listen 443 ssl;  
server\_name [www.domain.com](http://www.domain.com);  
error\_log /var/www/domain/logs/error\_log warn;  
ssl\_certificate /etc/nginx/certs/www.domain.com.crt;  
ssl\_certificate\_key /etc/nginx/certs/www.domain.com.key;  
root /var/www/domain/html/http;  
index index.php;  
client\_max\_body\_size 250m;  
error\_page 403 404 =404 /notfound;  
include /etc/nginx/conf.d/domain.locations;  
}

#### Content of domain.locations

```
    if ( $request_uri ~ "^/index.php" ) {
            rewrite ^/index.php(.*) $1 permanent;
    }
    location / {
            rewrite ^/wanted/feed$ /feed?filter=wanted permanent;
            try_files $uri $uri/ /index.php?$args;
    }
    location /min {
            try_files $uri $uri/ /min/index.php?q=;
    }
    location /blog {
            try_files $uri $uri/ /blog/index.php?q=$1;
    }
    location /apc {
            try_files $uri $uri/ /apc.php$args;
    }
    location /projects {
            internal;
            root /var/www/domain/html/files;
    }
    location ~ \.php {
            include /etc/nginx/fastcgi_params;
            fastcgi_param HTTPS $https if_not_empty;
            fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_script\_name;  
fastcgi\_param SERVER\_NAME $http\_host;  
fastcgi\_pass 127.0.0.1:9000;  
}  
location ~\* ^.+.(ht|svn|git)$ {  
deny all;  
}

```
    # Static files location
    location ~*

```

^.+.(jpg|jpeg|gif|png|ico|css|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$  
{  
expires max;  
}

Posted at Nginx Forum:

> **[rewrite or internal redirection cycle while internally redirecting to...](https://forum.nginx.org/read.php?2,234501,234501#msg-234501)**
>
> Hello everyone, I'm having some issue with X-accel and I'd be happy if someone could look over my configuration file and let me know what I did wrong. I am basically running nginx/1.2.5 with php-fpm 5.3.3 on Centos 5.5 I am running an application...
