# Nginx rewrite help

**URL:** <https://www.ruby-forum.com/t/nginx-rewrite-help/195647>\
**Category:** NGINX\
**Created:** [September 27, 2010, 3:38pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/195647 "2010-09-27T15:38:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvidinli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/45deac/32.png) [@bvidinli](https://www.ruby-forum.com/u/bvidinli)\
**Post date:** [September 27, 2010, 3:38pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/195647/1 "2010-09-27T15:38:26Z")

</div>

Hi,

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

this is working:  
[http://destek.10tl.net/forumdisplay.php?fid=40](http://destek.10tl.net/forumdisplay.php?fid=40)

but this is not working:  
[http://destek.10tl.net/Forum-40.html](http://destek.10tl.net/Forum-40.html)

my nginx conf related part is:

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

```

/mybb/forumdisplay.php?google\_seo\_forum=$2;  
if ($host !~\* server2.10tl.net) {  
rewrite (.\*) /mybb/$1 break;  
}

```
    }

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

                    # server2.10tl.net 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_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}

I expect this part:  
rewrite ^/mybb/((?i)Forum-([^./]+))$  
/mybb/forumdisplay.php?google\_seo\_forum=$2;

to translate Forum-40.html to forumdisplay.php?fid=40 and show it as if  
in  
[http://destek.10tl.net/forumdisplay.php?fid=40](http://destek.10tl.net/forumdisplay.php?fid=40)

I also tried with following in config, at top:

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

```

/mybb/forumdisplay.php?google\_seo\_forum=$2;  
}

thanks for your helps.

---

<div class="post-metadata">

**Author:** ![bvidinli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/45deac/32.png) [@bvidinli](https://www.ruby-forum.com/u/bvidinli)\
**Post date:** [September 27, 2010, 4:00pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/195647/2 "2010-09-27T16:00:41Z")

</div>

Hi,

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:

> **[Re: nginx rewrite help](https://forum.nginx.org/read.php?2,134553,134565#msg-134565)**
>
> Hi, I have a forum site, (with multi-forum) this is working: http://destek.10tl.net/forumdisplay.php?fid=40 but this is not working: http://destek.10tl.net/Forum-40.html my nginx conf related part is:

---

<div class="post-metadata">

**Author:** ![bvidinli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/45deac/32.png) [@bvidinli](https://www.ruby-forum.com/u/bvidinli)\
**Post date:** [September 27, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/195647/3 "2010-09-27T17:11:33Z")

</div>

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$ 

```

/forumdisplay.php?fid=$1;  
rewrite ^/Forum-([0-9]+).html$  
/forumdisplay.php?fid=$1;  
}

when I write  
[http://destek.10tl.net/forum-40.html](http://destek.10tl.net/forum-40.html)  
or  
[http://destek.10tl.net/Forum-40.html](http://destek.10tl.net/Forum-40.html)

it is re-written to  
[http://destek.10tl.net/forumdisplay.php?fid=40](http://destek.10tl.net/forumdisplay.php?fid=40)

but,  
this time the problem is: the url showing in address bar is changing.  
What I want is: user should still see  
[http://destek.10tl.net/forum-40.html](http://destek.10tl.net/forum-40.html)  
in address bar, (after pressing enter/page loads) but it should process  
[http://destek.10tl.net/forumdisplay.php?fid=40](http://destek.10tl.net/forumdisplay.php?fid=40)  
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:  
[http://webboss.10tl.net/forum-48.html](http://webboss.10tl.net/forum-48.html)

thanks.
