IIS6伪静态配置(以实现wordpress固定链接/伪静态为例讲述)

By | 2013年12月19日

Windows系统下面实现伪静态的方法有很多,但一般采用安装伪静态组件来实现。本文将以wordpress的自定义固定链接(即实现伪静态)为例,讲述如何在windows的环境下实现伪静态。

1、我们必须先要明白为什么我们需要使用伪静态?
这个主要是从SEO的角度取考虑的。从多次实践中证明,搜索引擎蜘蛛比较青睐于静态页面(相对另外一种是动态页面)的静态URL,而静态页面又分为真静态和伪静态。真静态是服务器端真正存在一个静态页面,但静态页面具有更新困难、存储量大等缺点未必受人欢迎。于是,人们往往采用伪静态的方法用于网站以更好地获得好的搜索引擎排名。

2、安装IIS的URL REWRITE组件

点击这里下载IIS Rewrite组件

2 把压缩包解压,把里面的dll文件复制到C:\WINDOWS\system32\inetsrv\目录。在 IIS 管理器里选择网站,右键选择“属性”。打开属性窗口,选择ISAPI筛选器,点击添加,筛选器名称填“Rewrite”,可执行文件填上刚刚下载的dll路径,“C:\WINDOWS\system32\inetsrv\rewrite.dll”如下图所示:

点击确认,重启IIS服务器!!到这里,组件安装完成。

3、让wordpress完美实现自定义固定链接(即wordpress伪静态)。

进入wordpress后台/设置/固定链接,常用设置选择自定义结构。如果你非要选前面几个结构,那你没必要看本文,那不需要服务器支持伪静态。看本站的URL结构,我写的是: /%category%/%postname%/ 。至于为什么这样写,它对SEO有什么好处,你可以去问谷哥或度娘,不解析。确保站点根目录的.htaccess文件存在,并且可写。点击保存更改。此时,wordpress应该有修改你的.htaccess文件,看看我的.htaccess文件的内容:

view source

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

然后,IIS是不支持.htaccess文件的,我们还需要在站点根目录添加一个httpd.ini文件,看我的伪静态规则。

view source
print?
[ISAPI_Rewrite]
# 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?0?2
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]

上面两个文件在不同的网站程序有不同的伪静态规则,请安装自己的需要编写。
完成。到前台查看网站页面。如果没有出现404错误,那就表示你配置成功了。

4、关于IIS7的伪静态实现
另外,有些人使用的是IIS7,实现伪静态就更简单了,不需要.htaccess和httpd.ini文件,直接把伪静态规则写到站点根目录的web.config配置文件里就行了。

wordpress完全支持IIS7的伪静态,在上面第3步点击保存更改的时候,wordpress会自动生成web.config文件,并写上相应规则。看我在IIS7下面产生的文件。

view source
print?
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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常见固定链接结构
1)/%postname%/ or /%postname%.html
2)/%year%/%monthnum%/%postname%/ or /%year%/%monthnum%/%postname%.html
3)/post/%postname%.html
4)/%category%/%postname%/ or /%category%/%postname%.html

本人实际在IIS中装好rewrite组件后,还是不行,后台将seo liner插件和cache插件关掉后,还是不行,但是看动态地址发现可以正常显示,由于是IIS6环境,用到hpptd.ini文件上传至根目录后,对于“找不到文件”的这类由于url地址不对的问题已解决!新测可行!

发表回复