NGINX常用伪静态(rewrite)规则

# +-------------------------------------------------------------------------
# | .htaccess文件
# +-------------------------------------------------------------------------

# 处理“http://域名/”请求,重写到/page/index.php
location = / {
    rewrite ^/$ /page/index.php last;
}

# 处理“http://域名/new/*.html”请求,重写到/old/*.php
location ~* ^/new/(.*)\.html$ {
    rewrite ^/new/(.*)\.html$ /old/$1.php last;
}

# 处理“http://域名/*.html”请求,依次尝试/*.html/page/*.html@rewrite_to_php(命名locationlocation ~* \.html$ {
    try_files $uri /page$uri @rewrite_to_php;
}

# 命名location,将/*.html重写到/page/*.php
location @rewrite_to_php {
    rewrite ^(.*)\.html$ /page$1.php last;
}

Copyright © 2026 码农人生. All Rights Reserved