nginx (last/break) rewrites

I have a simple nginx rewrite here, using permanent flag, it works fine.

location /area1/ {
rewrite /area1/(.*)$ / permanent;
}

However i want to retain the initial url, which seems from research to just need the last or break flag instead.

location /area1/ {
rewrite /area1/(.*)$ / break;
}

After changing permanent for break (or last) , it just seems to ignore the redirect entirely.

Please can someone demonstrate a working internal redirect that retains the initial url - i know this should be simple but i have tried a ton of config variations around the above and nothing seems to work, redirect was more complex to start with but i have reduced it to its basic form just to get the syntax correct , and i'm still failing...

Among many pages i referenced, this is one - https://www.nginx.com/blog/creating-nginx-rewrite-rules/

    server {
       listen        80;
        root         /usr/share/nginx/html;
        access_log   /var/log/nginx/root_host.access.log  main;
        error_log    /var/log/nginx/root_host.error.log;


location /area1/ {
rewrite /area1/(.*)$ / break;
}



if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

        location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        try_files $uri $uri/ /index.php?$query_string;
        }


location / {
    try_files $uri $uri/ /index.php?$args;
}


}
1
задан 1 March 2017 в 23:51
1 ответ

Ваша перезапись ... последняя на самом деле ничего не делает.

Вы внутренне перезаписываете / area1 / на / , который затем внутренне переписывается в /index.php последним оператором try_files .

Без блока location / area1 / , ] / area1 / внутренне переписывается в /index.php последним оператором try_files .

0
ответ дан 4 December 2019 в 05:08

Теги

Похожие вопросы