nginx 2 conflicting rewrite rules - please help!

Discussion in 'Nginx' started by tomek493, Mar 31, 2013.

  1. #1
    Hey guys - I've been struggling for so long with this problem, and have absoloutley no idea what's going on [​IMG] Any help would be apprieciated.

    I have the following 2 rules:

    rewrite ^(/posts.php) /controllers/read/C_ReadAllPosts.php?type=$arg_type last; break;
    rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$1 last; break;

    Only the rule which comes first ever works. Taking out the break; statements causes only the last one to ever work. Making the second rule more explicit by matching [^\.php] also does not help.

    I don't know why this is - the rule which doesn't work returns a 404, even though it shouldn't - and is available if I put that rule first.

    Thank you so much for any help.

    Tom
     
    tomek493, Mar 31, 2013 IP
  2. goproxy

    goproxy Member

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #2
    Hi Tom,

    The () aren't necessary in the first rule, but that is just a detail.
    The most important thing is removing the break;

    I tried this and it works(test1.html and test2.html have different content and I know when is entering in each rule):
    rewrite ^/posts.php /test1.html?type=$arg_type last;
    rewrite ^/(.+)/?$ /test2.html?url=$1 last;
    Code (markup):
    So, for you this should work:
    rewrite ^/posts.php /controllers/read/C_ReadAllPosts.php?type=$arg_type last;
    rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$1 last;
    Code (markup):
     
    goproxy, Apr 11, 2013 IP