当前位置:首页 > WordPress教程 > 正文


不少朋友总是询问 WordPress 如何添加伪静态规则,今天幻杀就总结一下 IIS6/IIS7.5/Apache/Nginx/win2003/win2008四种环境下的伪静态规则,希望对大家有所帮助。其中IIS7.5的规则是目前最完美的哦

明明是六种为什么要说是四种呢?其实windows的主机在2003时为IIS6,而2008以后升级为了IIS7.5 所以IIS6的规则在IIS7.5不通用哦,其实我以前也很纠结的。弄了半天规则才发现,悲催了

检测主机是否支持伪静态的方法:在WP后台 > 设置 > 固定链接,设置为 非默认带?的那种结构,然后访问任何一篇文章,如果出现 404 错误,说明你的主机当前不支持 WordPress 伪静态。



IIS 环境是 Windows 主机常用的服务器环境,但网上很多规则其实并不完美,很多地方依旧有些无法设置的地方,但这个却可以,新建两个 txt 文件,将下面的代码分别添加到文件中:

第一个 web.config

<rule name="ChineseURL" stopProcessing="true">
<match url="^(tag|category)/(.*)$" />
<action type="Rewrite" url="ihuanurl.php"/>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<action type="Rewrite" url="index.php" />

第二个辅助文件 ihuanurl.php:


// IIS Mod-Rewrite
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
// IIS Isapi_Rewrite
else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
// Use ORIG_PATH_INFO if there is no PATH_INFO
if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )

// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
if ( isset($_SERVER['PATH_INFO']) ) {

// Append the query string if it exists and isn't null
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {





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

# 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站点的根目录即可。


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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

然后上传到 WordPress 站点的根目录,重命名为 .htaccess 即可


Nginx环境一般是Linux 主机 VPS或服务器用户用的比较多,这些用户一般都会自己配置Nginx,或者有专门的人帮你配置,打开 nginx.conf 或者某个站点的配置环境,比如 wpdaxue.com.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 即可。


上一篇: 下一篇:

716 条评论

  1. Hiya! I know this is kinda off topic however , I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest
    authoring a blog article or vice-versa? My website addresses a lot of the same subjects as yours and
    I believe we could greatly benefit from each other.
    If you’re interested feel free to shoot me an e-mail.
    I look forward to hearing from you! Fantastic blog by
    the way!

    2018年8月20日 17:08 评论
  2. I must thank you for the efforts you have put in penning this website.
    I am hoping to check out the same high-grade content
    by you later on as well. In truth, your creative writing abilities has
    motivated me to get my own, personal site now ;)

    2018年8月20日 16:56 评论
  3. Hi! I could have sworn I’ve been to this site before but after browsing through some of the
    articles I realized it’s new to me. Nonetheless, I’m definitely
    pleased I found it and I’ll be book-marking it and checking back regularly!

    2018年8月20日 16:28 评论
  4. I read this paragraph fully concerning the difference of latest and earlier technologies, it’s amazing article.

    2018年8月20日 16:15 评论
  5. I couldn’t resist commenting. Well written!

    2018年8月20日 13:31 评论
  6. You have made some decent points there. I looked on the net to find out more about the
    issue and found most people will go along with your views on this site.

    2018年8月20日 13:20 评论
  7. Hi, I would like to subscribe for this webpage
    to get most recent updates, therefore where can i do it please assist.

    2018年8月20日 12:37 评论
  8. Howdy would you mind letting me know which hosting company you’re working with?
    I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a
    lot quicker then most. Can you suggest a good web hosting provider at a honest price?
    Kudos, I appreciate it!

    2018年8月20日 10:19 评论
  9. Hey there! This is kind of off topic but I need some help from an established blog.
    Is it very difficult to set up your own blog?
    I’m not very techincal but I can figure things out pretty
    quick. I’m thinking about making my own but I’m not sure
    where to begin. Do you have any ideas or suggestions?
    Thank you

    2018年8月20日 09:05 评论
  10. Keep on working, great job!

    2018年8月20日 07:19 评论