IIS环境下WordPress伪静态规则
IIS下安装WordPress一般不会出现什么问题,很严重的一个问题出在固定链接上,就是每个固定链接前面都要存在一个 index.php ,造成这种现象就是因为静态规则没有做好,如果你遇到了这种问题,请耐心看完本篇文章!
系统版本:Windows Server 2008 R2、Windows Server 2012 R2
网站环境:IIS7.5、IIS8.5+PHP7.0.2+IIS_Rewrite
伪静态程序:http://download.microsoft.com/download/4/E/7/4E7ECE9A-DF55-4F90-A354-B497072BDE0A/rewrite_x64_zh-CN.msi (无论是2008还是2012,R2都是64位的!如果需要32位的伪静态程序请点击这里下载!)
将微软发布的IIS_Rewrite安装之后,在网站根目录下建立一个名为 Web.Config 的文件,并将以下内容复制进去,保存。
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="category"> <match url="category/?(.*)"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> <action type="Rewrite" url="/index.php?category_name={R:1}" appendQueryString="false" logRewrittenUrl="false"/> </rule> <rule name="tags"> <match url="tag/?(.*)"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> <action type="Rewrite" url="index.php?tag={R:1}"/> </rule> <rule name="Main Rule" stopProcessing="true"> <match url=".*"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> </conditions> <action type="Rewrite" url="index.php/{R:0}"/> </rule> <rule name="wordpress" patternSyntax="Wildcard"> <match url="*"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <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>
之后再去后台,找到固定链接,你会发现一切都恢复了!
发表评论