Nginx-重写
location / {
rewrite ^/(\d+).html$ $1.html last;
}
Rewrite的Flags
-
Rewrite的Flags
- last – 基本上都用这个Flag。
- break – 中止Rewirte,不在继续匹配
- redirect – 返回临时重定向的HTTP状态302
- permanent – 返回永久重定向的HTTP状态301
- 一般在非根的location中配置rewrite,都是用的break;而根的location使用last比较好,因为如果配置了fastcgi或代理访问jsp文件的话,在根location下用break是访问不到
- ~ is case-sensitive match;
- ‘~’表示大小写敏感的匹配
- ~* specifies a case-insensitive match (firefox matches FireFox)
- ‘~*’表示大小写不敏感的匹配(例如:“firefox”字符串可以成功匹配“FireFox”)
- !~ and !~* mean the opposite, “doesn’t match”
- !~和!~*代表跟后面的正则匹配规则相反的规则,表示不能匹配当前正则表达式规则的字符串执行后面的处理语句
- checking for the existence of a file using the -f and !-f operators;使用-f参数以及!-f参数检测一个文件是否存在
- checking existence of a directory using the -d and !-d operators;使用-d参数以及!-d参数检测一个目录(路径)是否存在
- checking existence of a file, directory or symbolic link using the -e and!-e operators;使用-e以及!-e检测是否存在一个文件,一个目录或者一个符号链接。
- checking whether a file is executable using the -x and !-x operators.使用-x以及!-x检测一个文件是否可执行
- Parts of the regular expressions can be in parentheses, whose value can then later be accessed in the$1 to $9 variables.
- 正则表达式部分可以嵌套,表达式后面的部分如果用到前面的表达式可以用 $1 到$9 变量表示。
规则:
正则表达式形式的模式匹配,如~*和~