First look at a complete code example, about nginx 301 302 jump.
301 Jump Settings:
server { listen 80; server_name phpky.com; rewrite ^/(.*) http://www.45it.net/$1 permanent; access_log off; }
302 Jump Settings:
server { listen 80; server_name phpkyr.com; rewrite ^/(.*) http://www.45it.net/$1 redirect; access_log off ; }
See the detailed documentation on the nginx 301 302 jump
server { server_name 45it.net; rewrite ^/(.*) http://www.45it.net /$1 permanent; }
last – Basically use this Flag. Break – aborts Rewirte, does not continue to match redirect – returns temporary redirected HTTP status 302 permanent – returns permanent redirected HTTP status 301
Nginx redirect uses Nginx's HttpRewriteModule, as explained below The following how to use the method: rewrite command
nginx rewrite is equivalent to apache rewriterule (in most cases you can use the original apache rewrite rule with quotes can be used directly), it can be used in the server, In the location and IF conditional decision block, the command format is as follows: rewrite The regular expression replaces the target flag tag The flag tag can be used in the following formats: last – Basically use this Flag. Break – abort Rewirte, not continue matching redirect – return temporary redirected HTTP status 302 permanent – return permanent redirected HTTP status 301
Special Note:
last and break are used to implement URL rewriting, the URL address of the browser address bar is unchanged, but the path of the server-side access has changed;
redirect and permanent are used to implement URL jump, browse The address bar will display the URL address after the jump;
For example, the following section sets nginx to redirect files under one directory to another directory, and $2 corresponds to the second bracket (.*). Corresponding string: location /download/{ rewrite ^(/download/.*)/m/(.*)\\..*$ $1/nginx-rewrite/$2.gz break; } IF condition judgment of nginx redirection
In the case of server and location, you can use the IF condition of nginx to judge. The conditions can be as follows: Regular expression
For example: Match judgment ~ To distinguish between case and case; ~ is case-insensitive. ~* is case-insensitive; !~ is not case-insensitive. For example, set ngi below. Nx is redirected to the /nginx-ie directory when the user uses IE: if ($http_user_agent ~ MSIE) { rewrite ^(.*)$ /nginx-ie/$1 break; } File and directory judgment -f and !- f judge whether there are files -d and !-d to determine whether there is a directory -e and !-e to determine whether there is a file or directory -x and !-x to determine whether the file is executable. For example, the following setting nginx does not exist in files and directories Redirect: if (!-e $request_filename) { proxy_pass http://127.0.0.1; } return
Return the http code, for example set the nginx anti-theft chain: location ~* \\.(gif|
Jpg|
Png|
Swf|
Flv)$ { valid_referers none blocked www.45it.net www.test1.com; if ($invalid_referer) { return 404; } }
1. start --- & gt; control panel --- & gt; management tools --- & gt; Internet In
Dynamic feedback load balancing algorithm considers the real-time load and respon
I. Summary This article summarizes how to enable Gzip compression for websites hosted with IIS, the
What happened, my homepage could not be accessed? ! Hey, this free sp
How to use phpmyadmin to set the permissions of the mysql database user
IIS "ip address and domain name restrictions" setting method
Pseudo-static rules and settings in IIS
IIS7/iis7.5 pseudo-static plus sign and space error solution
ASP can't update ACCESS database solution
Data center energy consumption reduction Eight extreme methods revealed
Efficient management server to extract 3 tips
Master emergency: What should I do if the server data is accidentally lost?
Master teaches you the configuration and management of Apache server
How to cancel the power-on password and power-on login box
What should I do if the scroll bar at the bottom of the win7 folder runs to the right?
What if Windows 10 can't start an app with an administrator account?
How does Win10 turn test mode on and off? How to turn test mode on and off
Intel CPU causes Win8 to crash solution
How to use the Rubik's cube to set the Win8 eye protection color
Easily get unused IP addresses in Win XP
Win7 Bluetooth headset connected to the computer detailed tutorial
What should I do if the crack card is not used under Win 7 or is not normal?