Nginx将some / url重写为some / url.html

时间:2019-03-21 10:31:54

标签: nginx

我有NGINX服务器,我需要将所有链接http://some/url重定向到http://some/url.html

这三个条件:request_uri不为空,最后没有斜杠,URL也不以“ .html”结尾

我尝试过:

server {
  ...
  rewrite ^/(.+[^/])(?!.*\.html)$ $1.html permanent;
}

但这不起作用。

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试这样

server {
  server_name some;
  ...
  location /url {
    try_files $uri $uri.html =404;
  }
  ...
}