独家改写

时间:2014-09-30 19:11:32

标签: nginx rewrite

我需要重写路径a/<SEGMENT>,其中段不是xy。我如何在nginx中执行此操作?在Apache中,我会遵循以下规则来执行此操作:

RewriteCond %{REQUEST_URI} !^/a/x
RewriteCond %{REQUEST_URI} !^/a/y
RewriteRule ^a/(.+)$ script.php

谢谢!

1 个答案:

答案 0 :(得分:0)

通常,nginx会首先尝试匹配最具体的位置。因此,如果/ a / x或/ a / y不匹配,则匹配默认位置:

location / {
    try_files /script.php =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ ^/a/(?:x|y) {
    try_files $uri $uri/ =404;
}