使用 Simple Machines Forum 重写 Nginx

使用 Simple Machines Forum 重写 Nginx

我正在运行 Nginx 1.5.6,并使用 Simple Machines Forum 软件。大多数重写规则似乎都正常工作,但 RSS 源除外。

在我的 Nginx 配置中,我有以下行用于处理包含“.xml”的 URL:

rewrite ^/forum/(\.xml|xmlhttp)/?$ "/forum/index.php?pretty;action=$1" last;

上述规则为主论坛生成了以下 URL,该 URL 返回 403 错误:http://www.mydomain.com/forum/.xml/?type=rss

我希望重写规则生成这种类型的 URL,返回代码 200(真实页面):http://www.mydomain.com/forum/?type=rss;action=.xml

以下是与论坛重写相关的整个内容:http://pastebin.com/raw.php?i=tZkAibW3

非常感谢有人能帮我创建一条重写规则来实现这一点。谢谢。

答案1

您不能在rewrite子句中包含查询字符串(这需要mapor if)。像下面这样怎么样?

rewrite ^/forum/rss\.xml$ /forum/index.php?pretty;action=.xml last;

您的用户可以通过以下方式直接访问您的信息流http://mydomain.com/forum/rss.xml


好吧,Simple Machines 真是一团糟,但是根本没有一个好的论坛软件(我一直在考虑为这个任务启动我自己的开源项目)。

请尝试以下操作(纠正您的错误if用法):

server {
  location / {
    location ~ /forum/ {
      location ~ /forum/(\.xml|xmlhttp) {
        if ($args ~ type=rss) {
          rewrite ^/(.*)$ /forum/index.php?pretty;action=$1 last;
          try_files $uri @forum;
        }
      }
      try_files $uri @forum;
    }
  }
  location @forum {
    # Rules for: profiles
    rewrite ^/forum/profile/([^/]+)/?$ "/forum/index.php?pretty;action=profile;user=$1" last;

    # Rules for: actions
    rewrite ^/forum/(activate|admin|ads|announce|attachapprove|ban|boardrecount|buddy|calendar|clock)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(collapse|convertentities|coppa|credits|deletemsg|detailedversion|display|dlattach|editpoll|editpoll2)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(emailuser|featuresettings|findmember|groups|help|helpadmin|im|jseditor|jsmodify)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(jsoption|lock|lockvoting|login|login2|logout|manageboards|managecalendar|managesearch|manageattachments|maintain|markasread|mascot)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(membergroups|mergetopics|mlist|moderate|modifycat|modifykarma|movetopic|movetopic2|news|notify)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(notifyboard|optimizetables|openidreturn|packages|permissions|pm|post|postsettings|post2|printpage|profile|quotefast)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(quickmod|quickmod2|recent|regcenter|register|register2|reminder|removepoll|removetopic2)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(repairboards|reporttm|requestmembers|restoretopic|reports|search|search2|sendtopic|serversettings|smileys|smstats|suggest)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(spellcheck|splittopics|stats|sticky|theme|trackip|about:mozilla|about:unknown)/?$ "/forum/index.php?pretty;action=$1" last;
    rewrite ^/forum/(unread|unreadreplies|verificationcode|viewErrorLog|viewmembers|viewprofile|vote|viewquery|viewsmfile|who)/?$ "/forum/index.php?pretty;action=$1" last;

    # Rules for: boards
    rewrite ^/forum/([-_!~*'()$a-zA-Z0-9]+)/?$ "/forum/index.php?pretty;board=$1.0" last;
    rewrite ^/forum/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ "/forum/index.php?pretty;board=$1.$2" last;

    # Rules for: topics
    rewrite ^/forum/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ "/forum/index.php?pretty;board=$1;topic=$2.0" last;
    rewrite ^/forum/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ "/forum/index.php?pretty;board=$1;topic=$2.$3" last;

    rewrite ^/(.*)$ /index.php?params=$1 last;
  }
}

相关内容