Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've the following nginx conf:

server {
    server_name tawp.in;

    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/app.py;
            uwsgi_param UWSGI_SETENV WIKISHORTIPY_SETTINGS=/home/yuvipanda/sites/wikishortipy/settings.py;
            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 tawp.in/r/3 to see the extra redirect.

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

share|improve this question
1  
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

2 Answers 2

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

 
discard

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.