【发布时间】:2011-08-06 06:04:57
【问题描述】:
当文件系统中存在特定文件时,我已经看到了一些重写$request_uri 并添加index.html 的方法,如下所示:
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
但我想知道是否可以实现相反的结果:
即当有人请求http://example.com/index.html时,他们会被重定向到http://example.com
因为 nginx 正则表达式是 perl 兼容的,所以我尝试了这样的方法:
if ( $request_uri ~* "index\.html$" ) {
set $new_uri $request_uri ~* s/index\.html//
rewrite $1 permanent;
}
但这主要是猜测,是否有任何描述 nginx 的 modrewrite 的好文档?
【问题讨论】: