nginx重写所有post,但不是CSS或JS

我有一个WordPress博客,我想redirect所有请求到一个特定的职位/页面,不包括js,css(和图像)。

所以example.com/some-post/必须redirect(临时)到exmaple.com/catch-all/

我正在玩这个,但似乎不工作(我不知道我需要使用$ uri):

if ($uri !~ \.css$) { set $redi C; } if ($uri !~ \.js$) { set $redi "($redi)J"; } if ($uri !~ /catch-all/$) { set $redi "($redi)P"; } if ($redi = CJP) { rewrite ^(.*)$ https://example.com/catch-all/ last; return 302; } 

使用空location块来避免redirect某些请求:

 location ~ \.css$ {} location ~ \.js$ {} location /catch-all/ {} location / { rewrite ^(.*)$ /catch-all/ redirect; }