问题
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