1

I am running Nginx 1.5.6 and I use the Simple Machines Forum software. Most rewrite rules seem to work properly, with the exception of the RSS feeds.

In my Nginx configuration, I have the following line which is supposed to handle URLs which contain ".xml":

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

The above rule produces the following URL for the main forum, which returns a 403 Error: http://www.mydomain.com/forum/.xml/?type=rss

I would like the rewrite rule to produce this type of URL, which returns code 200 (a real page): http://www.mydomain.com/forum/?type=rss;action=.xml

Here is the entire block pertaining to the forum rewrites: http://pastebin.com/raw.php?i=tZkAibW3

I would really appreciate some help to create a rewrite rule to do that. Thanks.

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
Kevin Worthington
  • 327
  • 2
  • 6
  • 19

1 Answers1

0

You can't include the query string in your rewrite clause (this would require a map or if). How about something like the following?

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

Your users could access your feed directly via http://mydomain.com/forum/rss.xml


Well, Simple Machines is a terrible mess, but there is simply not a single good forum software out there (was always thinking about starting my own open source project for this task).

Please try the following (correcting your evil if usage):

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;
  }
}
Fleshgrinder
  • 3,798
  • 2
  • 17
  • 20