Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Nginx:如果指定的路径为';没有找到?_Html_Nginx - Fatal编程技术网

Html Nginx:如果指定的路径为';没有找到?

Html Nginx:如果指定的路径为';没有找到?,html,nginx,Html,Nginx,例如,对于文件: dir1/ index.html index.html 如果用户访问/dir1/somefile,请加载/dir1/index.html。如果他们访问/somefile,请加载/index.html。我的很多目录都是动态生成的,所以我不想硬编码每个条件。是否有一种更简单的方法可以路由到最具体的回退index.html文件?我认为您可以这样实现—但我没有测试过: location / { try_files $uri $uri/ @rewrite; } locat

例如,对于文件:

dir1/
    index.html
index.html

如果用户访问
/dir1/somefile
,请加载
/dir1/index.html
。如果他们访问
/somefile
,请加载
/index.html
。我的很多目录都是动态生成的,所以我不想硬编码每个条件。是否有一种更简单的方法可以路由到最具体的回退
index.html
文件?

我认为您可以这样实现—但我没有测试过:

location / {
  try_files $uri $uri/ @rewrite;
}

location @rewrite {
  rewrite ^(.*)/[^/]$ $1/index.html last;
}