Another rewrite question http://www.domain.com/co/

I have tried tons of combinations without any luck:

I want to get this rule:

http://www.domain.com/uk/ → index.php?country=uk

From Apache:
RewriteRule ^({2,}/)$ index.php?country=$1
RewriteRule ^({2,})$ index.php?country=$1
RewriteRule ^({2}/)index.php$ index.php?country=$1

I tried in location /:
rewrite “^({2}/)$” index.php?country=$1 break;
rewrite “^/({2}/)$” index.php?country=$1 break;

What I’m missing?

Posted at Nginx Forum:

Try this:

rewrite ^/([a-zA-Z]+)/$ /index.php?country=$1 break;

The forum ate some of your rules, here is the right one (I think):

rewrite ^/([a-z]{2})/?$ /index.php?country=$1 break;

Basically, do no use quotes.

I already tried this one.

I’m using quotes due to the brackets {}, if I don’t use them, nginx
fails to read the config, as {} are used by nginx config.

I have:

location / {
some-non-rewrite-rules-only-basic-config-rules
if (!-e $request_filename) {
go to index.php
}
rewrite ^/()/?$ /index.php?country=$1 break;
}

And it still doenst works.

Thnx for your help.

Posted at Nginx Forum:

As usual, my fault :wink:

The problem was the “rule order”.

            if (!-e $request_filename) {
                    rewrite ^(.*)$ /index.php last;
                    break;
            }

           rewrite "^/({2})/?$" /index.php?country=$1 last;

The first rule stopped the second one from working.

Posted at Nginx Forum: