Typecho博客初始安装完成后,博客的任何内页面或地址栏都会有index.php,都会在域名后加上 index.php,很多人都接受不了。
例如,我的博客网址: https://richerdyoung.com/index.php/p/75.html
但是,我希望最终的形式是这样: https://richerdyoung.com/p/75.html
那么,我们如何做到这样的效果?
一、配置服务器的 rewrite 伪静态规则
Nginx
主要关注nginx配置文件,例如:nginx.conf
server {
listen 80;
server_name richerdyoung.com;
root /home/laofan/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/richerdyoung.com.log combined;
}
Apache
主要是修改 .htaccess 文件。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
宝塔面板
宝塔面板分为LNMP和LAMP两种环境,由于LAMP环境没有预设typecho的伪静态代码,这里大家可以参考上面手工添加。
这里我重点讲一下,宝塔面板的LNMP如何设置typecho伪静态?
例如:
- 登录宝塔面板
- 网站
- 设置
- 伪静态
- 选择typecho
- 保存配置完成
注意:
选择typecho时,还会有typecho2的选择。
如果是使用域名直接安装的博客,例如本站:https://fujieace.com 为博客首页,那么请选择typecho。
如果域名已经有其它主页,希望在二级子目录来安装博客,例如:https://fujieace.com/typecho 为博客首页,那么请选择typecho2。
二、 typecho 后台配置伪静态
在 typecho 后台,开启伪静态,并选择你喜好的 url形式:
网站设置-》永久链接,选择启用地址重写功能。
例如:
- 登录管理界面
- 设置
- 永久链接
- 启用地址重写功能
- 勾选仍然启动此功能
- 选择wordpress风格
- 保存设置