如何用nginx重写这个url

时间:2015-06-06 05:54:45

标签: nginx

我试图在nginx服务器中重写这个网址

http://www.example.com/vb/?f=118&page=8

http://www.example.com/vb/forumdisplay.php?f=118&page=8

但它不与我合作

我用这个

rewrite ^/vb/(.*)f=(.*) /vb/forumdisplay.php?f=$2 permanent;

我的nginx服务器配置是

server {
        listen *:80;
        server_name     www.gem-flash.com;
        rewrite_log on;
        error_log   /var/log/nginx/a.gem-flash.com.log error;
        root   /home/gemnew/public_html/;
        error_page 404 /404.shtml;
        rewrite ^/vb/archive/index.php/t-([0-9]+)\.html /vb/showthread.php?t=$1 permanent;
        rewrite ^/vb/archive/index.php/f-([0-9]+)\.html /vb/forumdisplay.php?f=$1 permanent;
        rewrite ^/vb/archive/index.php/f-([0-9]+)-p-([0-9]+)\.html /vb/forumdisplay.php?f=$1&page=$2 permanent;
        rewrite ^/vb/archive/index.php/t-([0-9]+)-p-([0-9]+)\.html /vb/showthread.php?t=$1&page=$2 permanent;
        rewrite ^/vb/showthread.php?t=([0-9]+)&langid=1 /vb/showthread.php?t=$1 permanent;
        rewrite ^/~gemflash/vb(.*) /vb$1 permanent;
        rewrite ^/vb/vb/(.*) /vb/$1 permanent;
        rewrite ^/vbtest/(.*) /vb/$1 permanent;
        rewrite ^/vb/forum.php /vb/ permanent;
        rewrite ^/vb/(.*)f=(.*) /vb/forumdisplay.php?f=$2 permanent;
        rewrite ^/index.html /vb/ permanent;
        rewrite ^/vb/((urllist|sitemap).*.(xml|txt)(.gz)?)$ /vb/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
        error_page 404 /404.shtml;
        location  /404.shtml {
        internal;
}

1 个答案:

答案 0 :(得分:-1)

我刚刚在我自己的NGINX配置中尝试了这个重写URL,最后得到了以下一行:

rewrite ^/vb/?f=(.*) /vb/forumdisplay.php?f=$1 permanent;

你能给它一些测试吗?

泰斯