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
|
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 / {
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; }
location ~ /\.ht { deny all; } }
|
- 后台配置Typecho实现静态化
- 第一步完成后,登录博客后台,进入 设置→永久链接
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]
|