常见程序 nginx 伪静态规则

0 Share

常见程序 nginx 伪静态规则

Wordpress,Drupal,Twip,Typecho,Discuz,Dabr,Xnote 在 Nginx 中的伪静态规则

自从买了VPS,就经常痒痒着装上各种程序来体验。虽然lnmp一键安装包附带了几个伪静态规则,仍免不了自己写一些nginx的伪静态规则。

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;
	}
}

打包下载:nginx-rewrite.zip

Comments ( 6 )

  1. Reply宅男
    现在的空间就是vpsyou的?速度很快哈哈
    • Reply卢达
      现在是hugege的一号主机。xnote.in在vpsyou上。
  2. Reply宅男
    已经下载,覆盖了我的lnmp 嘎嘎
  3. Replydeardongdong
    少了一个emlog的!
    • Reply卢达
      其实,它和 Dabr 是一样地
  4. Replymuskelaufbaeu
    Your advice is quite useful.

Leave a reply

Your email address will not be published.