SaBlog-X2.0在nginx的完美伪静态规则分享


非常喜欢sablog-x这个博客,在服务器部署了之后,发现默认之后apache的伪静态规则。网上有很多的转换网站,首先找了一个站点把apache静态规则翻译成nginx能看懂的格式:

其实翻译后的规则nginx还是会报错的,我给改好了,提供给大家,这个SaBlog-X2.0在nginx的完美伪静态规则还是不错的:


location / {
	if (-f $request_filename){
	set $rule_0 1;
	}
	if (-d $request_filename){
	set $rule_0 1;
	}
	if ($rule_0 = "1"){
	#ignored: "-" thing used or unknown variable in regex/rew
	} 
	# 归档
        rewrite ^/date/([0-9]+)/([0-9]+)/page/([0-9]+)?/?$ /index.php?action=article&setdate=$1&setday=$2&page=$3 last;
        rewrite ^/date/([0-9]+)/([0-9]+)/?$ /index.php?action=article&setdate=$1&setday=$2 last;
        rewrite ^/date/([0-9]+)/page/([0-9]+)?/?$ /index.php?action=article&setdate=$1&page=$2 last;
        rewrite ^/date/([0-9]+)/?$ /index.php?action=article&setdate=$1 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|list|article|links)/?$ /index.php?action=$1 last;

	# 全部评论、标签列表、带分页
        rewrite ^/(comments|tagslist|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;

	# 搜索结果
        rewrite ^/search/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&searchid=$1&page=$2 last;

	# tags
        rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&tag=$1&page=$2 last;

	# 文章
        rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;

	# RSS
        rewrite ^/rss/([0-9]+)?/?$ /rss.php?cid=$1 last;
        rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;

	# 用户
        rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last;
        rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;

	# 自定义链接这个要屏蔽掉,不使用。
        #rewrite ^/([^/]+)/?([0-9]+)?/?$ /index.php?action=show&alias=$1&page=$2 last;

	# 地图文件
        rewrite  ^/sitemap\.xml$  /sitemap.php last;
}

Update:

上面的伪静态存在问题,就是如果的某些文件的即使时候也会出现错误,这是因为自定义了URL导致的

那到底怎么修改呢,

建议屏蔽:

rewrite ^/([^/]+)/?([0-9]+)?/?$ /index.php?action=show&alias=$1&page=$2 last;


关键词: rewrite , 伪静态 , nginx

上一篇: mysql主从数据实时复制实现数据同步配置教程(超简单)
下一篇: jQuery统计输入框字符数或者类似评论字数,即时统计

目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):