博主

昨天 19:30在线

拂晓不辍
如果是珍贵的回忆,怎么能够忘记,因为人死了,就只能活在别人的回忆里了。
歌曲封面 未知作品

萌ICP备20259933号

网站已运行 53 天 17 小时 24 分

Powered by Typecho & Sunny

2 online · 69 ms

拂晓不辍 人生最糟糕的事,一个是饿肚子,一个是孤独。《夏日大作战》
Title

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

拂晓不辍

·

📚️学习到知识

·

Article

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

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

配置服务器的rewrite规则
Linux Apache 环境 (.htaccess):

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

Linux Nginx 环境:

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

Windows 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]

1Panel/EServer 环境:

♾️ html 代码:
    location / {
    try_files $uri $uri/ /index.php$uri?$query_string;
}
或
location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}

后台配置typecho伪静态
如图,在typecho后台,开启伪静态,并选择你喜好的url形式:
2674244677.webp
具体操作,根据本人实际操作如下:

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

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

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

现在已有 41 次阅读,1 条评论,0 人点赞
Comment:共1条
发表
  1. 头像
    @

    博主

    冷冰冰
    这篇是偷泽泽社长的,hh
    · iPhone · Safari · 中国移动

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 网站设置有【CDN】缓存,留言评论或部分独立页面需要12小时才能更新显示! 不再显示
博主