重写nginx中根文件的规则? [英] Rewrite rule for the root file in nginx?

查看:61
本文介绍了重写nginx中根文件的规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将/重定向到不同的文件,而不是 index.php/.html.

I just want to redirect / to a different file rather than index.php/.html.

所以在 apache 上我可以做到这一点..

So on apache I can do this..

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . /path/to/dir/index.html [L]

在 nginx 中尝试这个甚至没有运行,似乎:

Trying this in nginx just doesn't even get run, it seems:

if (-f $request_filename){
    set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
    rewrite /. /path/to/dir/index.html last;
}

也试过这个:

if ($request_filename ~ "/index.php"){
    set $rule_3 1$rule_3;
}

if ($args ~ "^$"){
    set $rule_3 2$rule_3;
}

if ($rule_3 = "21"){
    rewrite /. /wp-content/plugins/i-static/content/index.html last;
}

它就像它甚至不存在一样,只是打印出 index.php.

It acts like it doesn't even exist and just prints out index.php.

推荐答案

如果要隔离单个 URI /,请使用 location = 变体.试试:

If you want to isolate the single URI /, use the location = variant. Try:

location = / { rewrite ^ /new/index.html last; }

这将执行内部重写.有关详细信息,请参阅本文档.

This will perform an internal rewrite. See this document for details.

这篇关于重写nginx中根文件的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆