[英]Set Nginx redirect rule priority
I have nginx+php-fpm and some rewrite rules for sef-urls. 我有nginx + php-fpm和一些sef-url的重写规则。
The problem is that all my custom redirects/rewrites are ignored and request going to php script instead redirecting. 问题是我所有的自定义重定向/重写都被忽略,请求转到php脚本而不是重定向。
Part for sef-links: sef链接的一部分:
if ($request_filename !~ ".(png|gif|ico|swf|jpe?g|js|css)$"){
set $rule_0 1$rule_0;
}
if (!-f $request_filename){
set $rule_0 2$rule_0;
}
if (!-d $request_filename){
set $rule_0 3$rule_0;
}
if ($rule_0 = "321"){
rewrite /. /index.php?sef_rewrite=1 last;
}
And I want to do that redirect: 我想重定向:
location = /first.html {
return 301 /second.html;
}
You need to thing in terms of nginx's locations and rules. 您需要根据Nginx的位置和规则进行操作。 Then it will be much easier to write proper config. 然后,编写适当的配置会容易得多。 Try this one: 试试这个:
location / {
# replacement for last three `if`s
try_files $uri $uri/ /index.php?sef_rewrite=1;
}
# here is you redirect
location = /first.html {
return 301 /second.html;
}
# this is replacement for first `if`
location ~ \.(png|gif|ico|swf|jpe?g|js|css)$ {
# serve static files
}
# I'm sure you have this block somewhere
location ~ \.php$ {
# serve php
}
Also these articles worth to read them: 这些文章也值得阅读:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.