1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

nginx rewrite rules

Discussion in 'Server Configuration and Hosting' started by MattW, Oct 29, 2013.

  1. MattW

    MattW 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/(.*) http://cdn.z22se.com/userpix/$1 [QSA,L]
            RewriteRule ^guides/(.*) http://cdn.z22se.com/guides/$1 [QSA,L]
    I've managed to get these to rewrite correctly by putting these in the server block

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

Share This Page