Typecho程序优势与伪静态必要性
尽管老左博客使用的是WordPress程序,但不得不承认WP在资源消耗方面表现欠佳。许多使用WP搭建博客的用户都经历过,当网站访问量达到几百时,普通主机的CPU负载极易超标,甚至导致主机服务被暂停。鉴于一般主机对CPU的限制通常在5%至10%之间,这种瓶颈非常常见。相比之下,Typecho是由国人开发的博客程序,虽已停止更新,但功能已相当完善。其结构类似WordPress,但在资源占用上远优于WP,因此拥有大量用户群体。
与WordPress不同,Typecho的伪静态规则并非默认启用,必须手动添加到服务器空间配置中才能生效。下文汇总了该程序在不同主机环境下的伪静态配置方案,旨在协助用户顺利完成设置。
Linux Apache与Nginx环境配置
1、Linux Apache环境(.htaccess):
RewriteEngine On
# 下面是在根目录,文件夹要修改路径,如 /laozuo/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# 带 www 的跳转到不带的
RewriteCond %{HTTP_HOST} ^www.laozuo.org
RewriteRule (.*) http://laozuo.org/$1 [R=301,L]
# 不带 www 的跳转到带的
RewriteCond %{HTTP_HOST} ^laozuo.org
RewriteRule (.*) http://www.laozuo.org/$1 [R=301,L]
2、Linux Apache环境(Nginx):
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;
}
}
Windows IIS环境伪静态规则
3、Windows IIS伪静态(httpd.ini):
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# 中文tag解决
RewriteRule /tag/(.*) /index\.php\?tag=$1
# sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# 内容页
RewriteRule /(.*).html /index.php/$1.html [L]
# 评论
RewriteRule /(.*)/comment /index.php/$1/comment [L]
# 分类页
RewriteRule /category/(.*) /index.php/category/$1 [L]
# 分页
RewriteRule /page/(.*) /index.php/page/$1 [L]
# 搜索页
RewriteRule /search/(.*) /index.php/search/$1 [L]
# feed
RewriteRule /feed/(.*) /index.php/feed/$1 [L]
# 日期归档
RewriteRule /2(.*) /index.php/2$1 [L]
# 上传图片等
RewriteRule /action(.*) /index.php/action$1 [L]
由于作者仅测试了Apache环境,故上述规则在Apache下确认可用。其他环境的用户可自行验证,若遇到问题欢迎留言反馈。