Nginx配置history模式,实现重写URI

2024-01-04 20 次阅读
Nginx

比如我们要配置这样一个地址http://webxue.cn/demo/

bash 复制代码
// demo.conf
location /demo/ {
  alias /home/project/webxue.cn/demo/;
  index index.html;
  # 重要是这行
  try_files $uri $uri/ /demo/index.html;
}

比如我们需要访问http://webxue.cn/demo仍然可以跳转到http://webxue.cn/demo/,就需要做uri重写

bash 复制代码
// demo.conf
location /demo {
  rewrite ^/demo/?$ /demo/ permanent;
}