0

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)

Yuvi
  • 101
  • 3

2 Answers2

1

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;
0

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

rewrite ^/r/([^/]*)$ /s/ta/$1 last;
rewrite ^/e/(.*)$ /en/ta/$1 last;
Mathias R. Jessen
  • 24,907
  • 4
  • 62
  • 95