正在阅读:

IIS7.5下实现wordpress完美伪静态

14,541

WordPress在windows下面布署比较麻烦,尤其是伪静态设置,IIS6和IIS7.5的设置也不同,之前本人博客有发过一个IIS6的设置,今天测试博客于是把网站架设在IIS7.5下,又遇到了伪静态的问题,还好网上有前辈设置过,转发过来。

wordpress

1、下载URL重写组件

微软官方下载 百度网盘下载

详细教程请点击http://www.xuexb.com/html/iis7_5url.html

2、IIS7.5下Wordpress伪静态设置

新建一个"chineseurl.php"文件:

<?php

// IIS Mod-Rewrite
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
}
// IIS Isapi_Rewrite
else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
else
{
// Use ORIG_PATH_INFO if there is no PATH_INFO
if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
$_SERVER['PATH_INFO'] = $_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']) ) {
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
}

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

require("index.php");

?>

修改 web.config 文件:

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

两个文件都保存在 WordPress 的安装目录下。

若 WordPress 不是装在根目录,则需要修改"<match url="^(tag|category)/(.*)$" />"为"<match url="^安装目录/(tag|category)/(.*)$" />"。如果在固定链接设置里把默认的标签前缀和分类目录前缀(tag 和 category)改了,则更改这句里的对应内容即可。

参考文章:

http://www.xuexb.com/html/iis7_5url.html

http://blog.csdn.net/zhangxiangyu0731/article/details/8482054

目前有:1条访客评论,博主回复1

  1. 胡迪
    2016-09-19 19:30

    谢谢博主,这个真解决了我的问题,之前Windows旧版的 突然间升级IIS7.5 除了主页其他网页都打不开,终于在这里找到了解决的方法,非常感谢!

留下脚印,证明你来过。

*

*

流汗坏笑撇嘴大兵流泪发呆抠鼻吓到偷笑得意呲牙亲亲疑问调皮可爱白眼难过愤怒惊讶鼓掌