typecho伪静态设置

文章目录
  1. 1. 一、根目录
  2. 2. 二、子目录
  • 参考资料
  • 一、根目录

    1、LinuxApache环境(.htaccess):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     <IfModule mod_rewrite.c>
    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 (.*) https://www.laozuo.org/$1 [R=301,L]
    </IfModule>

    2、LinuxApache环境(Nginx):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    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;
    }
    }

    3、Windows IIS伪静态(httpd.ini):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    [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]

    二、子目录

    第一、根目录Typecho 规则

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    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;
    }
    }

    第二、子目录伪静态规则

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    location /子目录文件夹/ {
    if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php last;
    }
    if (!-f $request_filename){
    rewrite (.*) /子目录文件夹/index.php last;
    }
    }

    参考资料