你的位置:首页 > 服务器类

部分常用CMS的nginx伪静态规则

2012-03-15 浏览:(7861) 服务器类 评论(0)

WordPress

location / {
  if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
  }
  if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
  }
  if (!-f $request_filename){
    rewrite (.*) /index.php;
  }
}

WordPress Mu

location /{
  server_name_in_redirect off;
  port_in_redirect off;

  rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1;
  rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1;

  if (!-e $request_filename) {
  rewrite ^.+?(/wp-.*) $1 last;
  rewrite ^.+?(/.*\.php)$ $1 last;
  rewrite ^ /index.php last;
  }
}

Drupal

location / {
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?q=$1 last;
  }
}

Twip

location /{
  if (!-e $request_filename){
    rewrite ^/(.*)$ /index.php last;
  }
}

Typecho

location / {
  index index.html index.php;
  if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
  }
  if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
  }
  if (!-f $request_filename){
    rewrite (.*) /index.php;
  }
}

Discuz

location / {
  rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
  rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
  rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
  rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
  rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
}

Discuz X

location / {
  rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
  if (!-e $request_filename) {
    return 404;
  }
}

Dabr

location / {
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?q=$1 last;
  }
}

SaBlog

location / {
  rewrite “^/date/([0-9]{6})/?([0-9]+)?/?$” /index.php?action=article&setdate=$1&page=$2 last;
  rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last;
  rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
  rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
  rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
  rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;
  rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last;
  rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;
  rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
  rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
  rewrite sitemap.xml sitemap.php last;
  rewrite ^(.*)/([0-9a-zA-Z\-\_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;
        }

Xnote

location / {
  if (!-e $request_filename) {
    rewrite "^/([A-Za-z0-9\-]{4,20})$" /index.php?url=$1 last;
  }
}

Status.net

location / {
  if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
  }
  if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
  }
  if (!-f $request_filename){
    rewrite (.*) /index.php;
  }
}

PHP-Wind

location / {
rewrite ^thread-htm-tid-(\d+)-(.*).html  thread.php?fid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html  read.php?tid=$1 last;
rewrite ^commtopics-(.*)-(.*)  thread.php?fid=$1&page=$2 last;
rewrite ^commtopics-(.*)       thread.php?fid=$1&page=$2 last;
rewrite ^article-(.*)-(.*)-(.*).html  read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*)-(.*).html       read.php?tid=$1&page=$2&fpage=$3 last;
rewrite ^article-(.*).html            read.php?tid=$1 last;
rewrite ^read-htm-tid-(\d+)-(.*).html  read.php\?tid=$1 last;
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
rewrite ^(.*)/u/([0-9]+)$ $1/u.php?uid=$2 last;
}

Bo-Blog

location / {
   if (!-e $request_filename)
   {
      rewrite ^/post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?entryid=$1&page=$2&part=$3 last;
      rewrite ^/page/([0-9]+)/([0-9]+)/?$ /index.php?mode=$1&page=$2 last;
      rewrite ^/starred/([0-9]+)/?([0-9]+)?/?$ /star.php?mode=$1&page=$2 last;
      rewrite ^/category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=category_$1&mode=$2&page=$3 last;
      rewrite ^/archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 last;
      rewrite ^/date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=showday_$1-$2-$3&mode=$4&page=$5 last;
      rewrite ^/user/([0-9]+)/?$ /view.php?go=user_$1 last;
      rewrite ^/tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /tag.php?tag=$1&mode=$2&page=$3 last;
      rewrite ^/component/id/([0-9]+)/?$ /page.php?pageid=$1 last;
      rewrite ^/component/([^/]+)/?$ /page.php?pagealias=$1 last;

      #Force redirection for old rules
      rewrite ^/read\.php/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
      rewrite ^/post/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
      rewrite ^/post/([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/ permanent;
      rewrite ^/post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/$3/ permanent;
      rewrite ^/index\_([0-9]+)\_([0-9]+)\.htm$ http://$host/page/$1/$2/ permanent;
      rewrite ^/star\_([0-9]+)\_([0-9]+)\.htm$ http://$host/starred/$1/$2/ permanent;
      rewrite ^/category\_([0-9]+)\.htm$ http://$host/category/$1/ permanent;
      rewrite ^/category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/category/$1/$2/$3/ permanent;
      rewrite ^/archive\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/ permanent;
      rewrite ^/archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/$3/$4/ permanent;
      rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/ permanent;
      rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/$4/$5/ permanent;

      #Filename alias
      rewrite ^/([a-zA-Z0-9_-]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?blogalias=$1&page=$2&part=$3 last;
   }
}

  • 发表评论
  • 查看评论
【暂无评论!】

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。