nginx rewrite syntax

rewrite syntax

  • last - basically use this Flag
  • break - Abort Rewirte, no more matching
  • redirect – returns HTTP status 302 for temporary redirection
  • permanent – ​​returns HTTP status 301 for permanent redirects

1. The following expressions can be used to judge:

-f 和 !-f 用来判断是否存在文件
-d 和 !-d 用来判断是否存在目录
-e 和 !-e 用来判断是否存在文件或目录
-x 和 !-x 用来判断文件是否可执行

2. The following are global variables that can be used as judgments

例:http://localhost:88/test1/test2/test.php?k=v
$host:localhost
$server_port:88
$request_uri:/test1/test2/test.php?k=v
$document_uri:/test1/test2/test.php
$document_root:D:\nginx/html
$request_filename:D:\nginx/html/test1/test2/test.php

redirect syntax

server {
    listen 80;
    server_name start.igrow.cn;
    index index.html index.php; root html; if ($http_host !~ "^star\.igrow\.cn$") { rewrite ^(.*) http://star.igrow.cn$1 redirect; } }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325019198&siteId=291194637