Comparing the return
, rewrite
, and try_files
Directives
The two directives for general‑purpose NGINX rewrite are return
and rewrite
, and the try_files
directive is a handy way to direct requests to application servers. Let’s review what the directives do and how they differ.
The return
Directive
The return
directive is the simpler of the two general‑purpose directives and for that reason we recommend using it instead of rewrite
when possible (more later about the why and when). You enclose the return
in a server
or location
context that specifies the URLs to be rewritten, and it defines the corrected (rewritten) URL for the client to use in future requests for the resource.
Here’s a very simple example that redirects clients to a new domain name:
server {
listen 80;
listen 443 ssl;
server_name www.old-name.com;
return 301 $scheme://www.new-name.com$request_uri;
}
Source: https://www.nginx.com/blog/creating-nginx-rewrite-rules/
Tool: http://www.anilcetin.com/
Comments are closed here.