Help translating Apache RewriteRules - Again, Thoroughly

Chris Cortese cortese.consulting at gmail.com
Thu Apr 8 12:44:02 MSD 2010


I'm still stumped on this one.  Can anyone tell why I'm getting an 
endless loop?  Firefox gives:

[code]
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this 
address in a way that will never complete.
   *   This problem can sometimes be caused by disabling or refusing to 
accept
           cookies.
[/code]



Machine:
[code]
. Ubuntu Karmic Koala fully-upgraded/updated, VM running on VMWare 
Workstation 6.5 running on Windows XP
. nginx 0.8.35 built from source
. php-5.3.2 with php-fpm
[/code]



Working .htaccess Apache file:
[code]
Options -Indexes

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z\/\-\_\@]+)$ index.php?demand=$1 [QSA,L]
#RewriteRule ^(.*)$ index.php?demand=$1 [NC,L]


<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
[/code]



My Nginx conf file:
[code]
server {
    listen 80;
   server_name  domain.com.vmware;

   access_log  /usr/local/nginx/logs/domain.com.access.log;
   error_log /usr/local/nginx/logs/domain.com.error.log debug;

   root /home/mylinuxuser/www/live/domain.com;
   index index.php;

   location / {
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_param SCRIPT_FILENAME 
/home/mylinuxuser/www/live/domain.com/index.php;
     include /usr/local/nginx/conf/fastcgi_params;
   }

   location ~ ^/([0-9a-zA-Z\/\-\_\@]+)$ {
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_param SCRIPT_FILENAME 
/home/mylinuxuser/www/live/domain.com/index.php;
     fastcgi_param QUERY_STRING      demand=$1;
     include /usr/local/nginx/conf/fastcgi_params0;
   }
}
[/code]

Here is the 5200-line debug output from the error log when only 
requesting http://domain.com

http://pastebin.com/6PLyC3r8



Note:  fastcgi_params is unmodified from nginx distribution.
	fastcgi_params0 is identical except it lacks QUERY_STRING setting


Note2:  I didn't write the web code.  There is PHP code doing a 
header("Location:... etc") call, in order to make clean URLs.  Still, if 
the PHP code works with the Apache .htaccess, it must be possible to 
have it work with Nginx configuration.

Can anyone help?


Thanks,
Chris





On 4/7/2010 1:06 AM, Igor Sysoev wrote:
> On Wed, Apr 07, 2010 at 12:05:07PM +0400, Igor Sysoev wrote:
>
>> On Wed, Apr 07, 2010 at 12:25:37AM -0700, Chris Cortese wrote:
>>
>>> Hello,
>>>
>>> I've been using nginx for 1.5 years now with about 10 or so CodeIgniter
>>> sites, but apparently I still haven't mastered the rewrite stuff.
>>>
>>> With the CodeIgniter stuff (and Igor's help), I never had to use the
>>> "rewrite" command at all.
>>>
>>> Anyway, now I need to translate the following (from .htaccess for Apache):
>>>
>>> RewriteRule ^([0-9a-zA-Z\/\-\_\@]+)$ index.php?demand=$1 [QSA,L]
>>>
>>> My current conf file is going into a loop and eventually returning nothing:
>>>
>>> server {
>>>     listen 80;
>>>     server_name  mysite.com.vmware;
>>>
>>>     access_log  /usr/local/nginx/logs/mysite.com.access.log;
>>>     error_log /usr/local/nginx/logs/mysite.com.error.log;
>>>
>>>     root /home/mylinuxuser/www/live/mysite.com;
>>>     index index.php;
>>>
>>>     rewrite ^/([0-9a-zA-Z\/\-\_\@]+)$ /index.php?demand=$1 last;
>>>
>>>     location / {
>>>       fastcgi_pass  127.0.0.1:9000;
>>>       fastcgi_param SCRIPT_FILENAME
>>> /home/mylinuxuser/www/live/mysite.com/index.php;
>>>       include /usr/local/nginx/conf/fastcgi_params;
>>>     }
>>> }
>>>
>>> --------------
>>>
>>> Can someone please advise?
>>
>>      location ~ ^/([0-9a-zA-Z\/\-\_\@]+)$ {
>>        fastcgi_pass  127.0.0.1:9000;
>>        fastcgi_param SCRIPT_FILENAME
>>                      /home/mylinuxuser/www/live/mysite.com/index.php;
>>        fastcgi_param QUERY_STRING    demand=$uri;
>
> A typo:
>
> -       fastcgi_param QUERY_STRING    demand=$uri;
> +       fastcgi_param QUERY_STRING    demand=$1;
>
>>        include /usr/local/nginx/conf/fastcgi_params0;
>>      }
>>
>>      location / {
>>        fastcgi_pass  127.0.0.1:9000;
>>        fastcgi_param SCRIPT_FILENAME
>>                      /home/mylinuxuser/www/live/mysite.com/index.php;
>>        include /usr/local/nginx/conf/fastcgi_params;
>>      }
>>
>> fastcgi_params0 is copy of fastcgi_params without QUERY_STRING parameter.
>>
>>
>> --
>> Igor Sysoev
>> http://sysoev.ru/en/
>>
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> http://nginx.org/mailman/listinfo/nginx
>




More information about the nginx mailing list