Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 Apache rules for a Web application that look like so:

RewriteEngine On
RewriteRule ^unsubscribe/([-A-z0-9]+)/?(.*)$ /list/unsubscribe.php?id=$1&why=$2 [L,QSA]
RewriteRule ^unsub/([-A-z0-9]+)/?(.*)$ /list/subscribe.php?id=$1&why=$2 [L,QSA]

I've tried:

rewrite ^unsubscribe/([-A-z0-9]+)/?(.*)$ /list/unsubscribe.php?id=$1&why=$2;

Which didn't seem to match and results in a 404.

    location /unsubscribe {
        rewrite ^/unsubscribe/([-A-z0-9]+)/?(.*)$ /list/unsubscribe.php?id=$1&why=$2 break;

Results in serving the file, but without PHP processed

Perhaps can someone recommend some debug strategies?

share|improve this question
up vote 0 down vote accepted

I don't have a debug strategy, so I am not 100% sure what nginx is doing. Though I rewrote the rewrite rules like so:

rewrite ^/unsubscribe/([a-zA-Z0-9]*)$ /list/unsubscribe.php?id=$1;
rewrite ^/unsub/([a-zA-Z0-9]*)$ /list/subscribe.php?id=$1;
rewrite ^/unsubscribe/([a-zA-Z0-9]*)/(.*)$ /list/unsubscribe.php?id=$1&why=$2;
rewrite ^/unsub/([a-zA-Z0-9]*)/(.*)$ /list/subscribe.php?id=$1&why=$2;

And it works. :)

share|improve this answer

The nginx Wiki states:

last - completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.

break - completes processing of current rewrite directives and non-rewrite processing continues within the current location block only.

So when using break, it will use the server {...}-wide root directive (I assume you have one) and serve the file statically.

You should rather try last in your rewrite rule, because then the PHP-processing route will match in a second turn and direct the request to PHP.

share|improve this answer
I added rewrite_log on; & error_log /tmp/rewrite.log notice;. I don't see any need by looking at the log: – hendry Aug 22 '13 at 8:15
My answer is just an alternative to yours and mainly for the purpose of better understanding the rewrite flags in nginx (break vs. last) because there's often confusion about what they do. – Lukas Aug 22 '13 at 13:32

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.