nginx rewrite expression dilemma

technoplague nginx-forum at
Mon Jun 25 10:39:18 UTC 2012


Having following apache config working: 


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


Rewrite works properly, when pointing to

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/;

server {
        error_log /data/www/dev/;

        charset utf-8;

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

        location / {
                root /data/www/dev/;
                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;

        location ~ (\.php)$ {
                fastcgi_param SCRIPT_FILENAME
                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:,227851,227851#msg-227851

More information about the nginx mailing list