Rewrite conversion

Hello,

I’m trying to convert from apache to nginx rewrite.

ErrorDocument 403 /index.php?do=/public/error/403/
ErrorDocument 404 /index.php?do=/public/error/404/

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteRule ^index.php(/.*)$ /index.php?do=$1 [L]

RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule ^(.*)$ /index.php?do=/$1 [L]

This is my try :smiley:

error_page 403 /index.php?do=/public/error/403/;
error_page 404 /index.php?do=/public/error/404/;

rewrite ^index.php(/.)$ /index.php?do=$1 last;
rewrite ^(.
)$ /index.php?do=/$1 last;

I have difficulty on REQUEST_URI with following paths.

any help is appreciated.

Thank you.
Tseveen.

On Sat, Jul 23, 2011 at 04:07:27PM +0900, Tseveendorj Ochirlantuu wrote:

RewriteCond %{REQUEST_URI} !^/install/.*
RewriteCond %{REQUEST_URI} !^/favicon.ico

I have difficulty on REQUEST_URI with following paths.

any help is appreciated.

server {

root  /path/to/files;

error_page 403  /index.php?do=/public/error/403/;
error_page 404  /index.php?do=/public/error/404/;

location /file/ {
}

location /install/ {
}

location /design/ {
}

location /plugins/ {
}

location = /robots.txt {
}

location = /favicon.ico {
}

location / {
    fastcgi_pass   ...
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
    fastcgi_param  QUERY_STRING     do=$uri;
}

location /index.php {

    location = /index.php {
        fastcgi_pass   ...
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
        fastcgi_param  QUERY_STRING     $args;
    }

    location ~ ^/index.php(/.*)$ {
        fastcgi_pass   ...
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
        fastcgi_param  QUERY_STRING     do=$1;
    }

    return 404;
}


Igor S.

Dear Igor,

Thank you for your conversion. It is working now.
I never imagine this apache rewrite would be like this.

Thank you very much again.

Tseveen.

Dear Igor,

I just tested rewrite but one thing did not work. When I’m accessing
http://www.xac.mn/index.php?do=/mytunes/view/song_40/module_popout/ this
popup but I got
404 Not Found

nginx/0.7.65
on the screen.Above url is working on Apache with rewrite.
I do not know difference between these two rewrites.
ApacheRewriteRule ^(.)$ /index.php?do=/$1 [L]
Nginxlocation ~ ^/index.php(/.
)$ { fastcgi_pass backend;
include fastcgi_params; fastcgi_param
SCRIPT_FILENAME
/var/www/xac/index.php; fastcgi_param QUERY_STRING
do=$1;
}

In my opinion : On apache rewrite do=/$1 slash stand before $1 but on
the
Nginx do=$1 without slash before $1. Is it same or different ? Because
above
link does not work.
Any help will be appreciated.
Thank youTseveen

On Sat, Jul 23, 2011 at 7:54 PM, Tseveendorj Ochirlantuu <

On Sat, Jul 23, 2011 at 9:33 PM, Tseveendorj Ochirlantuu
[email protected] wrote:

I do not know difference between these two rewrites.
Apache
RewriteRule ^(.)$ /index.php?do=/$1 [L]
Nginx location ~ ^/index.php(/.
)$ { fastcgi_pass backend;
include fastcgi_params; fastcgi_param
SCRIPT_FILENAME /var/www/xac/index.php;
fastcgi_param QUERY_STRING do=$1; }

the url
http://www.xac.mn/index.php?do=/mytunes/view/song_40/module_popout/
is handled by this location block:

   location = /index.php {
       fastcgi_pass   ...
       include        fastcgi_params;
       fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
       fastcgi_param  QUERY_STRING     $args;
   }

On 11.07.23 23:05, Edho A. wrote:

nginx/0.7.65
is handled by this location block:
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Really, I thought above rewrite handled by another. What do you think
this popup does not work ?

Dear Igor,

I have faced trouble on rewrite when new site installed on nginx. Most
script has pre-configured rewrite on apache.
Do you know what document is very useful for converting apache rewrite
to
nginx ? I will try learn for myself.

Thank you.
Tseveen.

On Sat, Jul 23, 2011 at 4:31 PM, Tseveendorj Ochirlantuu <

Dear Igor,

You have converted apache rewrite to nginx. I appreciated very much for
you.
But I need redirecting request www to non-www in my rewrite. Please
see your converted rewrite below.

Any help will be appreciated.

server {

root /path/to/files;

error_page 403 /index.php?do=/public/error/403/;
error_page 404 /index.php?do=/public/error/404/;

location /file/ {
}

location /install/ {
}

location /design/ {
}

location /plugins/ {
}

location = /robots.txt {
}

location = /favicon.ico {
}

location / {
fastcgi_pass …
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /path/to/files/index.php;
fastcgi_param QUERY_STRING do=$uri;
}

location /index.php {

   location = /index.php {
       fastcgi_pass   ...
       include        fastcgi_params;
       fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
       fastcgi_param  QUERY_STRING     $args;
   }

   location ~ ^/index.php(/.*)$ {
       fastcgi_pass   ...
       include        fastcgi_params;
       fastcgi_param  SCRIPT_FILENAME  /path/to/files/index.php;
       fastcgi_param  QUERY_STRING     do=$1;
   }

   return 404;

}

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