Rewrite rule for the root file in nginx?

拈花ヽ惹草 提交于 2021-01-28 15:54:09

问题


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

So on apache I can do this..

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

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;
}

Also tried this:

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;
}

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


回答1:


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.



来源:https://stackoverflow.com/questions/34625086/rewrite-rule-for-the-root-file-in-nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!