Redirecting to same page in case of resource not found - Nginx

Redirecting to same page in case of resource not found - Nginx



I have an use case where if page is refreshed, it should redirect back to the same page. For example
let's say I am on example.come/user/123. Now if I refresh the page, I should be redirected to same example.come/user/123 page. Following is part of my nginx configuration


server_name example.com ;
location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;


# define error page
error_page 404 = @notfound;

# error page location redirect 301
location @notfound
return 301 /;
# return 200 https://$host$request_uri;



This configuration returns me to my home page which is example.com. I understand how this redirection is working. But is it possible to redirect back to the same page from where page refresh was done?



I tried


return 200 https://$host$request_uri;



It redirects me to same page (example.com/user/123) but also automatically downloads a text document which contains url of the page.



example.com/user/123



Any help would be highly appreciated.




0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)