我们使用 WordPress 建站时,一般都是在 IIS/Apache/Nginx 这三种环境下搭建的,若你不知道自己 WordPress 所在的环境是什么,那么请去询问客服。

WordPress 伪静态之一:Nginx 伪静态规则

在 linux 系统中,Nginx 环境使用的人很多,如今市面上的 linux 主机 VPS 或服务器用户都在用这个,这些人一般都会自己配置配置 Nginx,或者有专门的人帮你配置,你只需要打开 nginx.conf 或者对应站点的配置文件,如 junzibuqi.com.conf(请根据你自己的来),在 conf 文件的 server{ } 大括号里面添加下面的代码:

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

将以上内容放入后记得保存,然后重启 Nginx 就可以使得你 WordPress 伪静态规则生效了。

WordPress 伪静态之一:Apache 伪静态

比起 Nginx 的伪静态,设置 Apache 的伪静态规则更简单,你只需要新建一个 htaccess.txt 文件,添加下面的代码:

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

保存之后,就将 htaccess.txt 文件上传到你 WordPress 网站的根目录,重命名为 .htaccess 即可生效。

WordPress 伪静态之一:IIS 伪静态规则

IIS 环境是 Windows 主机常用的服务器环境,直接新建一个 txt 文件,将下面的代码添加到文件中:

  1. [ISAPI_Rewrite]
  2. # Defend your computer from some worm attacks
  3. #RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . [F,I,O]
  4. # 3600 = 1 hour
  5. CacheClockRate3600
  6. RepeatLimit32
  7. # Protect httpd.ini and httpd.parse.errors files
  8. # from accessing through HTTP
  9. # Rules to ensure that normal content gets through
  10. RewriteRule/tag/(.*)/index.php?tag=$1
  11. RewriteRule/softwarefiles/(.*)/softwarefiles/$1 [L]
  12. RewriteRule/images/(.*)/images/$1 [L]
  13. RewriteRule/sitemap.xml /sitemap.xml [L]
  14. RewriteRule/favicon.ico /favicon.ico [L]
  15. # For file-based WordPress content (i.e. theme), admin, etc.
  16. RewriteRule/wp-(.*)/wp$1 [L]
  17. # For normal WordPress content, via index.php
  18. RewriteRule^/$ /index.php [L]
  19. RewriteRule/(.*)/index.php/$1 [L]

保存之后, httpd.ini 文件,上传到 WordPress 站点的根目录即可生效。