nginx位置在根目录之后重写任何内容
假设我有example.com,我想重写/to root之后的任何内容,即example.com/one/two?whatever=foo应该返回example.com 我尝试了以下方法:nginx位置在根目录之后重写任何内容,nginx,url-rewriting,Nginx,Url Rewriting,假设我有example.com,我想重写/to root之后的任何内容,即example.com/one/two?whatever=foo应该返回example.com 我尝试了以下方法: location = / { index index.html; } location / { rewrite ^ / permanent; } 但这给了我太多的重定向错误。我可以使用正则表达式指定所有允许/不允许的字符,但这会使它太难看/太长/太复杂 为什么精确匹配不能区分差异?您使用
location = / {
index index.html;
}
location / {
rewrite ^ / permanent;
}
但这给了我太多的重定向错误。我可以使用正则表达式指定所有允许/不允许的字符,但这会使它太难看/太长/太复杂
为什么精确匹配不能区分差异?您使用
index
指令执行从/
到/index.html
的内部重写。有关详细信息,请参阅
nginx
然后重新启动对匹配的位置的搜索,这将导致循环
您可以为/index.html
URI添加精确匹配,例如:
location = /index.html { }
如果index.html
引入本地资源(例如css、js、图像),您还需要专门处理这些URI