导航菜单

Typecho 默认的地址带有index.php这个文件,我很不喜欢,在TePass这个插件就强制要求开启伪静态,去掉index.php。

开启伪静态是很简单的,但是对于一些新用户来说,因设置不正确导致无法访问,其实就是两个步骤。

一.配置服务器的rewrite规则

根目录

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]

nginx 配置

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

location ~ .*\.php(\/.*)*$ {
    include fastcgi.conf;
    fastcgi_pass  127.0.0.1:9000;
}

apache 配置

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

其他

如果是宝塔面板,那就更简单了,如下图所示。
宝塔面板设置typecho伪静态.png

子目录

Nginx 配置

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

把上面伪静态规则中的foldername修改为子目录名称。

二、后台配置typecho伪静态

Typecho后台设置伪静态.png
typecho永久链接设置.png
如上图所示,选择你喜欢的URL形式即可,如果有个红色的框提示的话,勾选后再提交即可。

就这么两个步骤,但是缺一不可,简单吧~