Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've the following nginx conf:

server {

    location / {
            rewrite ^/r/([^/]*)$ /s/ta/$1;
            rewrite ^/e/(.*)$ /en/ta/$1;

            uwsgi_pass unix:/tmp/uwsgi.sock;

            uwsgi_param UWSGI_CHDIR  /home/yuvipanda/sites/wikishortipy;
            uwsgi_param UWSGI_CALLABLE app;
            uwsgi_param UWSGI_MODULE app;
            uwsgi_param UWSGI_FILE /home/yuvipanda/sites/wikishortipy/;
            uwsgi_param UWSGI_SETENV WIKISHORTIPY_SETTINGS=/home/yuvipanda/sites/wikishortipy/;
            include uwsgi_params;

I'd expect the two rewrite rules to just rewrite internally, but they're causing external 301 redirects to be sent. What am I doing wrong?

You can check the site at to see the extra redirect.

Edit: Adding the last flag to the rewrites doesn't help (as it shouldn't)

share|improve this question
What Location header is the 301 sending? Any chance that the python code is throwing it and not nginx? – Shane Madden Dec 30 '11 at 17:15
Python is sending the 301. But initial redirect from r/x to r/ta/x should be internal, no? – Yuvi Dec 31 '11 at 21:20

directive "break" will stop rewrite module working. If you using break inside location, your request will be proceed in it, so:

rewrite ^/r/([^/]*)$ /s/ta/$1 break;
rewrite ^/e/(.*)$ /en/ta/$1 break;
share|improve this answer

Try appending the last keyword to your rewrite rules, like this:

rewrite ^/r/([^/]*)$ /s/ta/$1 last;
rewrite ^/e/(.*)$ /en/ta/$1 last;
share|improve this answer
No luck - no effect in this case, just as the docs predicted – Yuvi Dec 30 '11 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.