Nginx rewrite help


I have a forum site, (with multi-forum)

this is working:

but this is not working:

my nginx conf related part is:

    location / {
        rewrite ^/mybb/((?i)Forum-([^./]+))$

if ($host !~* {
rewrite (.*) /mybb/$1 break;


    location ~ \.php$ {
                    set $test "";

                    # haric,
                    if ($host !~* server2\.10tl\.net) {
                            set $test  "${test}yaz";

                    # daha once mybb eklendiyse yukarda, bidaha

rewrite yapma.
# I am using nginx logical and-ing technique
as described in nginx site.

                    if ($request_filename !~* mybb) {
                            set $test  "${test}yaz";

                    if ($test = "yazyaz" ){
                            rewrite     (.*) /mybb/$1 break;

       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME 

include fastcgi_params;

I expect this part:
rewrite ^/mybb/((?i)Forum-([^./]+))$

to translate Forum-40.html to forumdisplay.php?fid=40 and show it as if

I also tried with following in config, at top:

    location ~ \.html$ {
            rewrite ^/mybb/((?i)Forum-([^./]+))$


thanks for your helps.


The rewrite you use contains /mybb/ but the URI does not. Rewrites work
on the URI and not the file path, so unless the information provided is
not accurate this is probably why your rewrite does not match.

Posted at Nginx Forum:,134553,134565#msg-134565

in fact, URI should not contain /mybb/
in php handling part, it is re-written to be /mybb/$1
to let php find that file in dir /mybb/

with my tests, I came to this point:

if I add this on top of conf:

    location ~ \.html$ {
            rewrite ^/forum-([0-9]+)\.html$ 

rewrite ^/Forum-([0-9]+).html$

when I write

it is re-written to

this time the problem is: the url showing in address bar is changing.
What I want is: user should still see
in address bar, (after pressing enter/page loads) but it should process
in background.

this is done in apache rewrite like this. and I (and my users) wants
this way.

can I achive this ?

here is a sample, similar site with apache running:


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs