nginx重定向:/ * /到/*.html(将.html添加到url)

时间:2017-12-31 13:57:21

标签: redirect nginx url-rewriting nginx-location

我想在每个以“/”结尾的文档中添加“.html”,但主页除外。

我尝试了一些使用重写的不同方法,并使用nginx返回301,但我没有让它工作。附上我做的最后一个版本,这是做/*/.html但第二个/不应该在那里。

location / {
    try_files $uri $uri/ =404;
    return 301 $scheme://$host$request_uri.html;
}

正在寻找的解决方案:

root:domain.com应以www.domain.com

发送 应将

文件重定向(301)到* .html版本

  • domain.com/abc/至domain.com/abc.html
  • domain.com/dir1/abc/到domain.com/dir1/abc.html

1 个答案:

答案 0 :(得分:1)

在尾随 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.paribu.com/ticker"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); 之前,您需要使用正则表达式来捕获URI 的一部分,以便消除它。一种解决方案是使用带有/语句的命名位置。

例如:

try_files

有关详情,请参阅this document