nginx rewrite rules


Well-known member
Since I've had the server running for a week, I've decided to tackle some of the errors that are now being logged.

These are mainly due to the old structure from a few years back, but a lot of other sites link to us still.

3 things I'm tackling initially:


I moved the forum to the root directory a few months back, so I've got this in my config to redirect all requests to forum to the root directory

  location /forum/ {
        rewrite ^/forum/(.*)?$ /$1 redirect;
        rewrite ^/forum$ / redirect;
That works fine

We then have 2 other folders. The userpix which used to reside in the forum folder, but I moved it to a different domain, and a guides folder that was in the root directory.

I had these rewriting in .htaccess with this:

        RewriteRule ^userpix/(.*)$1 [QSA,L]
        RewriteRule ^guides/(.*)$1 [QSA,L]
I've managed to get these to rewrite correctly by putting these in the server block

  rewrite ^(/guides/)(.*)$2 redirect;
  rewrite ^(/forum/userpix/)(.*)$2 redirect;
Is there a better way of rewriting these (in a location for example), rather than having them in the server block?