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

目录

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

1. 为什么需要使用伪静态?

这主要是从SEO的角度考虑的。从多次实践中证明,搜索引擎蜘蛛比较青睐于静态页面(相对另外一种是动态页面)的静态URL,而静态页面又分为真静态和伪静态。

  • 真静态:服务器端真正存在一个静态页面
  • 缺点:更新困难、存储量大
  • 伪静态:通过URL重写技术,将动态URL转换为静态形式

采用伪静态方法可以更好地获得好的搜索引擎排名。

2. 安装IIS的URL Rewrite组件

下载组件

点击这里下载IIS Rewrite组件

安装步骤

  1. 解压压缩包,将里面的dll文件复制到 C:\WINDOWS\system32\inetsrv 目录
  2. 在IIS管理器里选择网站,右键选择"属性"
  3. 打开属性窗口,选择"ISAPI筛选器"
  4. 点击"添加",筛选器名称填"Rewrite"
  5. 可执行文件填上dll路径:C:\WINDOWS\system32\inetsrv\rewrite.dll

[11]

  1. 点击确认,重启IIS服务器

至此,组件安装完成。

3. WordPress伪静态配置

WordPress后台设置

  1. 进入WordPress后台 → 设置 → 固定链接
  2. 常用设置选择"自定义结构"
  3. 设置URL结构,例如:/%category%/%postname%/

SEO建议/%category%/%postname%/ 结构对SEO有好处,具体原因可参考搜索引擎优化相关资料。

配置文件设置

.htaccess文件配置

确保站点根目录的.htaccess文件存在且可写,点击保存更改后,WordPress会自动生成以下内容:

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

httpd.ini文件配置

由于IIS不支持.htaccess文件,需要在站点根目录添加httpd.ini文件:

[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
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,实现伪静态更简单:

  • 不需要.htaccesshttpd.ini文件
  • 直接将伪静态规则写到站点根目录的web.config配置文件中

WordPress完全支持IIS7的伪静态,在后台保存固定链接设置时,WordPress会自动生成web.config文件:

<?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%//%postname%.html
  2. /%year%/%monthnum%/%postname%//%year%/%monthnum%/%postname%.html
  3. /post/%postname%.html
  4. /%category%/%postname%//%category%/%postname%.html

转自:http://www.uglycolor.net/develop/win2003-iis6-rewrite-wordpress/

💬 评论