# Nginx rewrite expression dilemma

**URL:** <https://www.ruby-forum.com/t/nginx-rewrite-expression-dilemma/220920>\
**Category:** NGINX\
**Created:** [June 25, 2012, 12:39pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-expression-dilemma/220920 "2012-06-25T12:39:42Z")\
**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:** [June 25, 2012, 12:39pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-expression-dilemma/220920/1 "2012-06-25T12:39:42Z")

</div>

Hi,

Having following apache config working:

=========================================================

```
<Directory /data/www/dev/domain.com/cf/htdocs/get>
    Options FollowSymlinks
    RewriteEngine on
    RewriteRule ^([^/\.]+)/([^/]+)$ index.php?contid=$1 [L]
</Directory>

```

=========================================================

Rewrite works properly, when pointing to [domain.com/get/aa/bb](http://domain.com/get/aa/bb)

I can’t get this working properly in nginx using the following config:  
When I enter URL that works in apache, nginx returns with 404.

=========================================================  
upstream cf-domain {

```
    server unix:/data/www/dev/domain.com/cf/cf-domain.sock;

```

}

server {  
listen 62.236.108.22:80;  
listen 127.0.0.1:28005;  
server\_name [cfdev.domain.com](http://cfdev.domain.com);  
access\_log  
/data/www/dev/domain.com/cf/logs/frontend/access.log;  
error\_log /data/www/dev/domain.com/cf/logs/frontend/error.log;

```
    charset utf-8;

    location ~ ^/get/ {
            rewrite ^([^/\.]+)/([^/]+)$ index.php?contid=$1 last;
            fastcgi_pass cf-domain;
    }

    location / {
            root /data/www/dev/domain.com/cf/htdocs;
            index index.php index.html;

            if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") {
                    expires max;
            }

            if (!-f $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
                    break;
            }
    }

    location ~ (\.php)$ {
            fastcgi_param SCRIPT_FILENAME

```

/data/www/dev/domain.com/cf/htdocs$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
fastcgi\_pass cf-domain;  
}

```
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

```

}

=========================================================

I suspect I need to amend processing order or rewrite, but can’t seem to  
find the right way. Can you please help me to find where the error is?

Posted at Nginx Forum:

> **[nginx rewrite expression dilemma](https://forum.nginx.org/read.php?2,227851,227851#msg-227851)**
>
> Hi, Having following apache config working: ========================================================= \<Directory /data/www/dev/domain.com/cf/htdocs/get\> Options FollowSymlinks RewriteEngine on Rewrit
