首页 > 建站技术 > wordpress win主机用404实现静态化

wordpress win主机用404实现静态化

win主机的wordpress用户可能会相当头痛静态化的问题,如果服务器没有
安装类似rewrite的组件的话,静态化将会相当的麻烦。不过呢,下面这段
代码为我们提供了另外一种简单的方式来实现静态化。

 <?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');
?>

设置固定链接(Permalink)伪静态步骤:
1. 将以上代码保存为 404.php,并上传至主机根目录。
2. 设置 404 自定义错误页为 404.php。
3. 进入 WordPress 控制面板,设置(Options)- 固定链接(Permalinks),选择固定链接格式。



类似“/2007/03/15/post-name/”式目录结构(例子:WordPress.com)
  Permalinks写法:/%year%/%monthnum%/%day%/%postname%/ 

类似“/2007/03/15/post-name.html”式目录结构(例子:boingboing.net)
  Permalinks写法:/%year%/%monthnum%/%day%/%postname%.html 

类似“/2007/03/post-name/”式目录结构(例子:WordPress.org blog)
  Permalinks写法:/%year%/%monthnum%/%postname%/ 

类似“/2007/03/post-name.html”式目录结构(例子:Blogger、TypePad)
  Permalinks写法:/%year%/%monthnum%/%postname%.html 

类似“/123.html”式目录结构(例子:livejournal、百度空间)
  Permalinks写法:/%post_id%.html 

我使用的“/category/post-name.html”式目录结构
  Permalinks写法:/%category%/%postname%.html

您必须在 登录 后才能发布评论.