Forum: NGINX Another rewrite question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
devin (Guest)
on 2009-04-14 00:20
(Received via mailing list)
I have tried tons of combinations without any luck:

I want to get this rule: -> 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:,1026,1026#msg-1026
Kiril A. (Guest)
on 2009-04-14 02:30
(Received via mailing list)
Try this:

rewrite  ^/([a-zA-Z]+)/$  /index.php?country=$1 break;
Kiril A. (Guest)
on 2009-04-14 02:32
(Received via mailing list)
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.
devin (Guest)
on 2009-04-15 02:31
(Received via mailing list)
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 / {
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:,1026,1044#msg-1044
devin (Guest)
on 2009-04-15 04:11
(Received via mailing list)
As usual, my fault ;)

The problem was the "rule order".

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

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

The first rule stopped the second one from working.

Posted at Nginx Forum:,1026,1045#msg-1045
This topic is locked and can not be replied to.