root /home/u1/domains/example.com;

location / {
  rewrite ^/page/(.*)$ /index.php?cstart=$1;

  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/page,([0-9]+),([0-9]+),(.*).html*$ /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&cstart=$5&news_name=$6;
  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/page,([0-9]+),(.*).html*$ /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5;
  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/print:page,([0-9]+),(.*).html*$ /engine/print.php?subaction=showfull&year=$1&month=$2&day=$3&news_page=$4&news_name=$5;
  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*).html*$ /index.php?subaction=showfull&year=$1&month=$2&day=$3&news_name=$4;

  rewrite ^/([^.]+)/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html(/?)$ /index.php?newsid=$4&news_page=$2&cstart=$3;
  rewrite ^/([^.]+)/page,([0-9]+),([0-9]+)-(.*).html(/?)$ /index.php?newsid=$3&news_page=$2;
  rewrite ^/([^.]+)/print:page,([0-9]+),([0-9]+)-(.*).html(/?)$ /engine/print.php?news_page=$2&newsid=$3;
  rewrite ^/([^.]+)/([0-9]+)-(.*).html(/?)$ /index.php?newsid=$2;

  rewrite ^/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html(/?)+$ /index.php?newsid=$3&news_page=$1&cstart=$2;
  rewrite ^/page,([0-9]+),([0-9]+)-(.*).html(/?)+$ /index.php?newsid=$2&news_page=$1;
  rewrite ^/print:page,([0-9]+),([0-9]+)-(.*).html(/?)+$ /engine/print.php?news_page=$1&newsid=$2;
  rewrite ^/([0-9]+)-(.*).html(/?)+$ /index.php?newsid=$1;

  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/page/([0-9]+)(.*)$ /index.php?year=$1&month=$2&day=$3&cstart=$4;
  rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)(.*)$ /index.php?year=$1&month=$2&day=$3;

  rewrite ^/([0-9]+)/([0-9]+)/page/([0-9]+)(.*)$ /index.php?year=$1&month=$2&cstart=$3;
  rewrite ^/([0-9]+)/([0-9]+)(.*)$ /index.php?year=$1&month=$2;

  rewrite ^/([0-9]+)/page/([0-9]+)(.*)$ /index.php?year=$1&cstart=$2;
  rewrite ^/([0-9]+)(.*)$ /index.php?year=$1;

  rewrite ^/catalog/([^/]*)/page/([0-9]+)(.*)$ /index.php?catalog=$1&cstart=$2;
  rewrite ^/catalog/([^/]*)(.*)$ /index.php?catalog=$1;

  rewrite ^/newposts/page/([0-9]+)(.*)$ /index.php?subaction=newposts&cstart=$1;
  rewrite ^/newposts(.*)$ /index.php?subaction=newposts;

  rewrite ^/static/(.*).html(.*)$ /index.php?do=static&page=$1;

  rewrite ^/user/([^/]*)/news/page/([0-9]+)(.*)$ /index.php?subaction=allnews&user=$1&cstart=$2;
  rewrite ^/user/([^/]*)/news(.*)$ /index.php?subaction=allnews&user=$1;
  rewrite ^/user/([^/]*)(.*)$ /index.php?subaction=userinfo&user=$1;
  rewrite ^/favorites /index.php?do=favorites;
  rewrite ^/favorites/page/(.*)$ /index.php?do=favorites&cstart=$1;
  rewrite ^/statistics.html$ /index.php?do=stats;
  rewrite ^/addnews.html(.*)$ /index.php?do=addnews;
  rewrite ^/rss.xml$ /engine/rss.php;
  rewrite ^/sitemap.xml$ uploads/sitemap.xml;

  if (!-d $request_filename) {
    rewrite ^/([^.]+)/page/([0-9]+)(.*)$ /index.php?do=cat&category=$1&cstart=$2;
    rewrite ^/([^.]+)/*$ /index.php?do=cat&category=$1;       
  }

  if (!-f $request_filename) {
    rewrite ^/([^<]+)/rss.xml$ /engine/rss.php?do=cat&category=$1;
    rewrite ^/page,([0-9]+),([^/]+).html$ /index.php?do=static&page=$2&news_page=$1;
    rewrite ^/([^/]+).html$ /index.php?do=static&page=$1;
  }
}

location /xfsearch {
  rewrite ^/xfsearch/([^/]*)/*$ /index.php?do=xfsearch&xf=$1;
  rewrite ^/xfsearch/([^/]*)/page/([0-9]+)/*$ /index.php?do=xfsearch&xf=$1&cstart=$2;
}

location ~ /\.svn {
  deny all;
}

location ~ /\.git {
  deny all;
}

location ~ /\.hg {
  deny all;
}

location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  try_files $uri =404;
}

location ~* (engine/cache) {
  deny all;
}

location ~ \.php$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $request_filename;
  fastcgi_intercept_errors on;
  fastcgi_pass unix:/var/run/php5-example.com.sock;
}
