不少朋友总是询问如何为WordPress添加伪静态规则?今天为大家分享一下IIS/Apache/Nginx 三种环境下的伪静态规则,希望对大家有所帮助。

检测主机是否支持伪静态的方A 0 }法:在WP后台 > 设置 > 固定链接,设置为 非默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。
IIS伪静态规则
IIS 环境是 Windows 主机常用的服务器环境,新建一个 txt 文件,将下面的代码添加到文件中:
[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.as| Y . v @ ! 6a|default\P M b B = P /.ida|root\.exe|\.\.).* . [F,I,O]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.! s K e = Tini and httpd.parse.errors files
# from accessing through HTTP
# Rules to4 s ; ensure that normal content gets through
Rewrit] k ? | _ LeRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /software-files/(.*) /softs ! { \ . ) zware-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
Rewritl } K U I : H w geRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicoQ b H $n.ico /favicon.ico [L]
#[ W l a Q \ L For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpressy k j h content, via index.php
RewriteRule ^/$ /index.ps z rhp [L]
RewriteRule /(.*) /index.php/$1 [L]
然后另存为 httpd.ini 文件,上传到WoC 4 l ` rrdPress站点的根目录即可u | u V y o e 0。
Apache伪静态规则
Apache是 Linux 主( g 0 – 4机下常见的环境,现在一般的 Linux 虚拟主机都采用这种环境。新建一个 htaccess.txt 文件,添加下面\ = )的代码:
<IfModule mod_rewrite.c>
Rewrite; X $ u ; V % EEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可
Nginx伪静态规则
NginY o K S kx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置NginC X #x,或者有专门的人帮你配置,打开n E : E ( C nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.conf(不同人配置的不一样),在 server { } 大括号里面添加下面的代码:
location / {
try_f3 T 7 I ; , 5 Siles $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-aZ % K K Edmin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
保存,重启 Nginx 即可。

