首页 > 服务器 > nginx rewrite配置

nginx rewrite配置

2009年03月30号
查看评论 发表评论 1,162次浏览

正则表达式匹配:

* ~ 为区分大小写匹配
* ~* 为不区分大小写匹配
* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配
文件及目录匹配:

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

* last 相当于Apache里的[L]标记,表示完成rewrite
* break 终止匹配, 不再匹配后面的规则
* redirect 返回302临时重定向
* permanent 返回301永久重定向
全局变量:

$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri
举例:
abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

if ($host ~* (.*)\.domain\.com) {
set $sub_name $1;
rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
}

类别服务器 标签
  1. admin
    发表于 2009年03月31号 00时03分42秒 | 1楼

    现在慢慢很多服务器都转向NG了!

  2. cheap basketball shoes
    发表于 2010年06月20号 04时42分46秒 | 2楼

    I’m in agreement

  3. james shoes
    发表于 2010年06月26号 19时01分52秒 | 3楼

    My dear,I love your comment and wisdom

  4. paul smith polo
    发表于 2010年07月02号 20时47分27秒 | 4楼

    Super post.

  5. Nike Air Force
    发表于 2010年07月24号 19时59分40秒 | 5楼

    Beautiful extracts of wisdom, thank you

  6. Herve Leger Sale
    发表于 2010年07月27号 13时38分34秒 | 6楼

    I really love them! There is so much hidden wisdom and subtle teaching in them.

  7. discount mbt shoes
    发表于 2010年08月06号 10时00分35秒 | 7楼

    You must be a wonderful person!

  1. 目前没有通告
你必需 登陆 才能发表评论.