自豪地使用 Typecho 建站

用心 记录着 生活点点滴滴

苏ICP备2021014930号

自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 1 人
歌曲封面 未知作品
  • 歌曲封面Good TimeCarly Rae Jepsen
  • 歌曲封面I Like Me BetterLauv
  • 歌曲封面Don't Wanna Know/We Don't Talk AnymoreSam Tsui / Alex Blue

自豪地使用 Typecho 建站

用心 记录着 生活点点滴滴

苏ICP备2021014930号

网站已运行 215 天 4 小时 0 分

Powered by Typecho & Sunny

2 online · 22 ms

许大阳的日记本 认为悲惨的话就反抗,心存懊悔的话就前进,只会为不幸哀叹的你,连猪都不如。
Title

BUG日记 ● Typecho 伪静态规则

许大阳

·

Article
很多人在搭建完博客后,访问博客的时候地址栏中会出现index.php,据说不利于网站的SEO。那么如何去掉index.php,让文章地址显示的更简洁些呢?

配置服务器的rewrite规则:

Typecho 无法自动配置,需要手动配置服务器的 rewrite 规则。

Linux Apache 环境 (.htac­cess):

♾️ html 代码:
<IfModule mod_rewrite.c>
RewriteEngine On
# 下面是在根目录,文件夹要修改路径
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Linux Apache 环境(Ng­inx):

♾️ html 代码:
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;
}
}

Win­dows IIS 伪静态 (httpd.ini):

♾️ html 代码:
[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]

ng­inx 配置:

♾️ html 代码:
server {
        listen          80;
        server_name     yourdomain.com;
        root            /home/yourdomain/www/;
        index           index.html index.htm index.php;

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

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

        access_log logs/yourdomain.log combined;
    }

apache 配置:

♾️ html 代码:
<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伪静态:

如图,在 type­cho 后台,开启地址重写,并选择你喜好的 url 形式:

现在已有 0 条评论,1 人点赞
Comment
发表
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主