WordPress伪静态原理与检测
所谓伪静态,是指网站底层仍为.php、.asp或.aspx等动态格式,且通过问号加参数读取数据库。启用该功能后,这些动态页面会被重写转换为类似静态页面的形式。
与其他多数具备自动生成静态页面功能的网站系统不同,WordPress主要依靠伪静态机制来处理URL结构。
目前绝大多数主机均支持伪静态功能。用户只需在空间管理后台选择对应的网站系统类型,空间便会自动适配该系统的伪静态规则。
判断空间是否支持伪静态的方法很简单:进入网站后台,依次点击“设置”-“固定链接”,选择一个非默认的选项保存。若此时访问其他页面出现404错误,则说明当前空间不支持伪静态。

只要空间支持URL Rewrite重写功能,根据具体的服务器环境,只需添加相应的伪静态规则代码即可生效。
Apache服务器伪静态规则配置
Apache服务器的伪静态规则配置
新建一个txt文本文件,将下方代码粘贴进去,保存时将文件名改为.htaccess,然后上传至WordPress站点的根目录。
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Nginx服务器伪静态规则配置
Nginx服务器的规则配置
在Nginx的server模块中添加以下配置。打开nginx.conf文件或特定站点的配置文件(如/usr/local/nginx/conf/yzipi.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){
IIS服务器的伪静态规则
}
}
IIS服务器伪静态规则配置
IIS伪静态规则配置
新建一个txt文本文件,将下方代码粘贴进去,保存时另存为httpd.ini文件,随后上传至WordPress站点的根目录。
[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]
参考链接:Apache Module mod_rewrite
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。