因为本人的博客是在windows主机上,呃,导致wordpress不能用apache mod_rewrite。之后采取404页面重写URL,代码如下:
- <?php
- $qs = $_SERVER['QUERY_STRING'];
- $_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
- $_SERVER['PATH_INFO'] = iconv(“GBK//IGNORE”, “UTF-8//IGNORE”, $_SERVER['REQUEST_URI']);
- include(‘index.php’);
- ?>
以为万事俱备了,呃,昨晚测试了下,竟然分页有问题。分页链接是http://xxxxx.com/your404page.php/directory/page/2?,且next post link的链接是http://xxxxx.com/your404page.php/directory/page/2?xxxxx.com/your404page.php/directory/page/2?。说明上面的404页面代码对wordpress的支持不是很好。现改成以下代码,支持得很好。收藏着以便日后之需。嘻嘻
- <?php
- // This is the default file for the site. Usually index.php
- $default = ‘index.php’;
- $thisfile = your 404 page;
- $_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
- $_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
- $_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);
- ?>
有1位同学留下了脚印
请问博主 “your 404 page”这里怎样填写啊,我是新手