Help translating Apache RewriteRules - Again, Thoroughly

Edho P Arief edhoprima at gmail.com
Thu Apr 8 13:06:05 MSD 2010


On Thu, Apr 8, 2010 at 3:44 PM, Chris Cortese
<cortese.consulting at gmail.com> wrote:
> 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]
>
>

simple way:

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;

  location ~ ^/[0-9a-zA-Z/\-_@]+$ {
    rewrite ^/([0-9a-zA-Z/\-_@]+)$ /index.php?demand=$1 last;
  }
  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include /usr/local/nginx/conf/fastcgi_params;
  }
}

faster way:

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;

  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;
  }
  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include /usr/local/nginx/conf/fastcgi_params;
  }
}


-- 
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the nginx mailing list