TA的每日心情 | 奋斗 2015-5-14 15:11 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
博客刚弄好就开始寻找方法伪静态了,因为做过SEO,老是感觉如果不静态了心里不踏实,其实好像搜索引擎对与静态与否已经没有多少区别了,不过还是喜欢静态的,哪怕是伪静态呢,看着也舒服啊。
于是搜了一些方法,基本上都是用404错误页面来完成的,此种方法好像不会对搜索引擎引起什么不良反应。但是发现很多都是没用的,测试了几家,没用一个能用的,最后终于找到了一个,公布一下方法(如果你的主机不能自定义404错误页的话,估计不好整):
<?php
// This is the default file for the site. Usually index.php
$default = 'index.php';
// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a '/' prefix in IIS).
$thisfile = '404-handler.php';
$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;
$qs =& $_SERVER['QUERY_STRING'];
$ru =& $_SERVER['REQUEST_URI'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, '?'), '?');
// Required for Wordpress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;
// Fix GET vars
foreach ( $_GET as $var => $val ) {
if ( substr($var, 0, 3) == '404') {
if ( strstr($var, '?') ) {
$newvar = substr($var, strpos($var, '?') + 1);
$_GET[$newvar] = $val;
}
unset($_GET[$var]);
}
break;
}
include($default);
?>
新建404.php将上面代码复制进去,放到网站根目录下,然后到IIS里,找到自定义错误,找到404错误选择编辑,消息类型选择URL 下面填/404.php保存。然后回到WordPress后台,当你的主机是Linux好了,想要什么样的URL自己设置吧~! |
|