Typecho配置Rewrite规则

1.Nginx

首先在你的Nginx服务器上配置了 yourdomain.conf 文件,注意不是 nginx.conf 文件,文件存储路径一般为

1
/usr/local/nginx/conf/vhost/yourdomain.conf

yourdomain.conf 配置文件中找到 server 配置段,在其中加入下面一段代码

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

而其他不需要修改,保存重启服务器。

例如我的配置文件为 www.conimi.com.conf ,配置完成如下,

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## Version 2022/10/04 - Changelog: https://github.com/linuxserver/docker-baseimage-alpine-nginx/commits/master/root/defaults/nginx/site-confs/default.conf.sample

server {
listen 80 default_server;
listen [::]:80 default_server;

listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

server_name _;

set $root /app/www/public;
if (!-d /app/www/public) {
set $root /config/www;
}
root $root;
index index.html index.htm index.php;
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php$1 last;
}

location / {
# enable for basic auth
#auth_basic "Restricted";
#auth_basic_user_file /config/nginx/.htpasswd;

try_files $uri $uri/ /index.html /index.php$is_args$args =404;
}

location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}

# deny access to .htaccess/.htpasswd files
location ~ /\.ht {
deny all;
}
}
  1. 后台配置Typecho实现静态化
  2. 第一步完成后,登录博客后台,进入 设置→永久链接

2.Apache

1.加载Rewrite模块

Apache/conf/httpd.conf配置文件中找到如下内容,去掉前面注释#去掉。

1
LoadModule rewrite_module modules/mod_rewrite.so

AllowOverride none 改成AllowOverride All

2.进入网站根目录,新建.htaccess并写入内容

1
2
3
4
5
6
RewriteEngine On 
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Typecho配置Rewrite规则
https://kuan.pages.dev/article/b82be445.html
作者
IKun
发布于
2023年1月25日
许可协议