Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a WordPress blog, and I'd like to redirect all requests to one certain post/page, excluding js, css (and images).

so must redirect (temporarily) to

I was playing around with this, but doesn't quite seem to work (I'm not sure I need to use $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 ^(.*)$ last;
        return 302;
share|improve this question
do not use if ($uri - use location – SaveTheRbtz Jan 17 '12 at 12:08
but you can't use location != /catch-all/$ as far as I know? – Tuinslak Jan 17 '12 at 12:27
regular expressions have thing called negative look behind. BTW do you really need != /catch-all/$? – SaveTheRbtz Jan 17 '12 at 13:37
With the IFs if I wouldn't include != /catch-all it would redirect that page as well (endless loop). – Tuinslak Jan 17 '12 at 14:33

Use empty location blocks to avoid the redirect for certain requests:

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.