我们使用WordPress建站时,一般都是在IIS/Apache/Nginx这三种环境下搭建的,若你不知道自己WordPress所在的环境是什么,那么请去询问客服。
WordPress伪静态之一:Nginx伪静态规则
在linux系统中,Nginx环境使用的人很多,如今市面上的linux主机 VPS或服务器用户都在用这个,这些人一般都会自己配置配置Nginx,或者有专门的人帮你配置,你只需要打开nginx.conf或者对应站点的配置文件,如junzibuqi.com.conf(请根据你自己的来),在conf文件的server{ } 大括号里面添加下面的代码:
- 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就可以使得你WordPress伪静态规则生效了。
WordPress伪静态之一:Apache伪静态
比起Nginx的伪静态,设置Apache的伪静态规则更简单,你只需要新建一个 htaccess.txt 文件,添加下面的代码:
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index.php$ – [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
保存之后,就将htaccess.txt文件上传到你WordPress网站的根目录,重命名为 .htaccess 即可生效。
WordPress伪静态之一:IIS伪静态规则
IIS 环境是 Windows 主机常用的服务器环境,直接新建一个 txt 文件,将下面的代码添加到文件中:
- [ISAPI_Rewrite]
- # Defend your computer from some worm attacks
- #RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . [F,I,O]
- # 3600 = 1 hour
- CacheClockRate 3600
- RepeatLimit 32
- # Protect httpd.ini and httpd.parse.errors files
- # from accessing through HTTP
- # Rules to ensure that normal content gets through
- RewriteRule /tag/(.*) /index.php?tag=$1
- RewriteRule /software–files/(.*) /software–files/$1 [L]
- RewriteRule /images/(.*) /images/$1 [L]
- RewriteRule /sitemap.xml /sitemap.xml [L]
- RewriteRule /favicon.ico /favicon.ico [L]
- # For file-based wordpress content (i.e. theme), admin, etc.
- RewriteRule /wp-(.*) /wp–$1 [L]
- # For normal wordpress content, via index.php
- RewriteRule ^/$ /index.php [L]
- RewriteRule /(.*) /index.php/$1 [L]
保存之后, httpd.ini 文件,上传到WordPress站点的根目录即可生效。