Nginx 重写任意目录结尾的URL添加index.html后缀
您可以使用nginx的rewrite指令来实现将任意目录结尾的URL重写为添加index.html后缀的URL。以下是一个示例配置:\n\nnginx\nserver {\n\tlisten 80;\n\tserver_name example.com;\n\n\troot /path/to/root;\n\n\tlocation / {\n\t try_files $uri $uri/ @rewrite;\n\t}\n\n\tlocation @rewrite {\n\t rewrite ^/(.*)/$ /$1/index.html;\n\t}\n}\n\n\n在上面的配置中,首先将根目录设置为/path/to/root,然后在location /中使用try_files指令来尝试匹配URI。如果无法找到对应的文件或目录,则将重写到@rewrite位置。\n\n在location @rewrite中,使用rewrite指令将任意目录结尾的URL重写为添加index.html后缀的URL。例如,example.com/foo/将被重写为example.com/foo/index.html。\n\n请注意,您需要将example.com替换为您自己的域名,并将/path/to/root替换为您的网站根目录的实际路径。
原文地址: https://www.cveoy.top/t/topic/puIZ 著作权归作者所有。请勿转载和采集!