Rewrite rules modify a part or whole of the URL. This is done for two reasons. First, to inform clients about the relocation of resources, and second, to control the flow to Nginx. The two general-purpose methods used widely for rewriting URLs are the return directive and the rewrite directive. Of these, the rewrite directive is more powerful. Let's discuss why it is so, as well as how to rewrite the URLs.
Having a better understanding of NGINX will make it easier to follow this blog.
Return directive
Return is the easiest way to rewrite a URL declared in the server or local machine.
Return in Server:
Suppose your site is migrated to a new domain and all existing URLs are to be redirected here; run the below code to direct any new request to your site.