yumen 发表于 2013-11-8 18:44:19

windows主机安装wordpress利用404.php实现伪静态

国内很多Windows主机没有安装URL Rewrite组件(ISAPI Rewrite),我们可以利用自定义错误页面来实现伪静态,从而可以设置想要的固定链接。一、将如下404.php放入网站根目录:<?php
$qs = $_SERVER['QUERY_STRING'];
$qsu = mb_convert_encoding("$qs", "UTF-8", "UTF-8");
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qsu, $pos);
if (strpos($_SERVER['REQUEST_URI'], '?') > 0) {
$_SERVER['SCRIPT_NAME'] = $_SERVER['ORIG_PATH_INFO'] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
$_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
} else {
$_SERVER['SCRIPT_NAME'] = $_SERVER['ORIG_PATH_INFO'] = $_SERVER['REQUEST_URI'];
$_SERVER['QUERY_STRING'] = '';
}
include("index.php");?>二、在主机后台设置“自定义出错页”为“使用web目录中的404.php文件来自定义内容”三、设置wordpress固定链接:
进入WP网站后台→“设置”→“固定链接”→勾选“自定义结构”,我个人推荐的固定链接格式是/%postname%/或者/%postname%.html这样的好处是部分关键词会出现在URL中,有利于SEO。

页: [1]
查看完整版本: windows主机安装wordpress利用404.php实现伪静态

a