Typecho设置伪静态隐藏掉网址中的index.php

Typecho设置伪静态隐藏掉网址中的index.php

2023年12月01日 作者头像 作者头像 泽泽社长 编辑

评论

0 Count

Typecho后台设置永久链接后,会在域名后加上index.php,很多人都接受不了。例如如下网址:

http://xxx.com/index.php/archives/233/,但我们希望最终的形式是这样:http://xxx.com/archives/233.html。那么我们如何做到这样的效果?

配置服务器的rewrite规则

Linux Apache 环境 (.htaccess):

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

Linux Nginx 环境:

if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }
如果在目录文件夹里则
location /文件夹名/ {
    if (!-e $request_filename) {
        rewrite ^(.*)$ /文件夹名/index.php$1 last;
    }
}

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]

1Panel/EServer 环境:

location / {
    try_files $uri $uri/ /index.php$uri?$query_string;
}

后台配置typecho伪静态

如图,在typecho后台,开启伪静态,并选择你喜好的url形式:

后台配置typecho伪静态.jpeg

具体操作,根据本人实际操作如下:

如果虚拟主机是apache的,在网站根目录找不到.htaccess,可能是设置了隐藏文件,显示隐藏文件就能看到了。

然后编辑.htaccess文件,加入上文中对应的apache配置代码保存。然后去typecho程序后台,设置>永久链接,按照上文中图片的设置,保存即可。

如果是宝塔面板就更简单了,宝塔里面直接内置里两套,一般选第一个就行,第二个是网站在文件夹里的情况,如文章上面所说。