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've been frustrated for days trying to figure this out, so any advice/help would be greatly appreciated!

I've recently added a section called /links to a site at but can't seem to get the rewrite rules going for this directory (see below). All other paths of the domain are working fine (say for example redirects to fine) and all other rewrite rules seem to still be working great, it's just the newly added location /links/ section to my conf where things fall apart.

The following conf fails on line 27 -- The error I get when using service nginx restart is: directive "rewrite" is not terminated by ";" but I can see that the end line terminates with a ; so I'm not sure what's wrong. Perhaps something with the regex?

My nginx conf is below. Any ideas on what to alter to get URLs like or working?


server {
  listen 80;
  root /var/www/;
  include /etc/nginx/php.conf;

  location / {
    index index.php;
    access_log /var/log/nginx/;

    #handle old variable redirects first, before dealing with current permalinks
    rewrite ^/?browse/video/(.*) /by/$1 permanent;

    #set a 30-day expires header on static files for cache
    if (-f $request_filename) { expires 30d; break; }    

    #do current permalinks with args
    try_files $uri $uri/ /index.php?$args;

  #handle static redirects from old URLs and rewrite
  location /browse/title { rewrite ^(.*)$ /browse/?orderby=title redirect; }
  location /browse/featured { rewrite ^(.*)$ /by/featured/ permanent; }

  #handle /links permalinks etc
  location /links/ {
    rewrite "tag/(.+)/page/([0-9]{1,})/s/([^/]+)(/)?"$ /?tag=$1&page=$2&s=$3 break;
    rewrite "tag/(.+)/page/([0-9]{1,})(/)?" /?tag=$1&page=$2 break;
    rewrite tag/(.+)/s/([^/]+)(/)? /?tag=$1&s=$2 break;
    rewrite tag/([^/]+)(/)? /?tag=$1 break;
    rewrite rss/([^/]+) /rss.php?tag=$1 break;
    rewrite rss /rss.php break;
    rewrite "page/([0-9]{1,})/s/([^/]+)" /index.php?page=$1&s=$2 break;
    rewrite "page/([0-9]{1,})" /index.php?page=$1 break;
    rewrite go/([0-9]+) /ir.php?id=$1 break;

share|improve this question

The dollar is outside of the quotes in the first regular expression of your rewrite.

share|improve this answer
Of course it answers the question, it's the syntax error that prevents the compilation of the configuration and thus no redirect is working, because nginx is refusing to apply the newly added location block. – Fleshgrinder Oct 14 '13 at 23:16
Oh, my bad, I misread. – Falcon Momot Oct 14 '13 at 23:17

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.