windows Server 2012 下WordPress IIS8.0伪静态规则设置
什么是伪静态?
网站还是动态的,以ASP或PHP结尾的文件,但是通过服务器组件使访问地址变成静态html的。例如你访问的地址是www.hnyqhg.com/1234.html,而服务器真正处理的可能是www.hnyqhg.com/index.asp?id=1234,这是为了用户体验和搜索引擎的优化。人们一般认为静态的页面有利于排名。
环境:
操作系统:Windows Server 2012
Web服务器:IIS 8.0
网站程序:WordPress
网站根目录:C:/wordpress
一、确认IIS 8.5是否安装IIS URL Rewrite
如果没有,则下载一个,IIS URL Rewrite下载地址:
双击默认安装即可,装完重启IIS
二、添加IIS 8.5伪静态规则文件
1、新建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> |
2、把web.config拷贝到网站根目录:C:/wordpress下
三、设置WordPress
进入网站管理后台
设置-固定链接-自定义结构
填写:/archives/%post_id%.html
保存
这样Windows Server 2012 下WordPress IIS8.0伪静态规则就设置好了,其他的网站设置的方法类似,希望对大家有帮助。