WordPress 伪静态规则(Apache/Nginx)

Apache伪静态规则

Apache是 Linux 主机下常见的环境,如今通常的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面的代码:php

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

而后上传到 WordPress 站点的根目录,重命名为 .htaccess 便可html

Nginx伪静态规则

Nginx环境通常是Linux 主机 VPS或服务器用户用的比较多,这些用户通常都会本身配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,好比 wpdaxue.com.conf(不一样人配置的不同),在  server   { } 大括号里面添加下面的代码:nginx

1
2
3
4
5
6
7
8
9
10
11
location / {if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
        }if (!-f $request_filename){
                rewrite (.*) /index.php;
        }}

保存,重启 Nginx 便可。服务器