标签存档: IIS

IIS上WordPress的固定链接问题

IIS上WordPress的固定链接不能做成这样的形式:
http://archangelsdy.com/2010-12/iis-wp-static-link/
上面的链接默认会404, 只能弄成如下形式:
http://archangelsdy.com/index.php/2010-12/iis-wp-static-link/
这样未免不太完美, 不过既然会404, 就可以在404页面上动点手脚, 一下是网上流传较广的404重定向修改页:


<?php
header("HTTP/1.1 200 OK");
$ori_qs = $_SERVER['QUERY_STRING'];
$pattern = '/[^;]+;[^:]+://[^/]+(/[^?]*)(?:?(.*))?/i';

preg_match($pattern, $ori_qs, $matches);
$_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2];
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
$query_args = explode('&', $matches[2]);
unset($_GET);
foreach ($query_args as $arg)
{
$the_arg = explode('=', $arg);
$_GET[$the_arg[0]] = $the_arg[1];
}

include('index.php');
?>

这个404.php挂了上去后, 链接是重定向正常了, 不过顶上华丽地顶着3个”offset error”, 貌似是数组越界, 看了下代码(其实完全不懂php…), 用到了$matches[]这个数组, 第一反应是添行if(count($matches)>=3)上去, 没想到真的成功了! 不知道有没有什么后遗症捏…

附改过的404.php, 有的主机可能要另外设一下404页面的位置.


<?php
header("HTTP/1.1 200 OK");
$ori_qs = $_SERVER['QUERY_STRING'];
$pattern = '/[^;]+;[^:]+://[^/]+(/[^?]*)(?:?(.*))?/i';

preg_match($pattern, $ori_qs, $matches);
if(count($matches)>=3)
{

$_SERVER['PATH_INFO'] = $matches[1] . '?' . $matches[2];
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
$query_args = explode('&', $matches[2]);
unset($_GET);
foreach ($query_args as $arg)
{
$the_arg = explode('=', $arg);
$_GET[$the_arg[0]] = $the_arg[1];
}

}
include('index.php');
?>