经验分享
Nginx配置history模式,实现重写URI
nginx配置history模式,主要解决刷新页面404的问题
2024-01-04 10:28:29
18

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

// 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重写

// demo.conf
location /demo {
  rewrite ^/demo/?$ /demo/ permanent;
}