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