wordpress设置漂亮固定连接时出错的解决方法

wordpress定义blog的固定连接分为三个档次

默认:“丑陋”

默认的链接如下

http://example.com/?p=N

mod_rewrite: “漂亮的链接”

使用mod_rewrite或lighttpd可以生成更好看的链接地址(查看 漂亮的链接),有各种个样的链接格式,最常见、最通用的格式如下

http://example.com/category/post-name/
or  http://example.com/year/month/day/post-name.html

PATHINFO: “比较好的链接”

PATHINFO类型的链接地址和mod_rewrite类型的地址看起来很像,唯一的区别是在前面多了/index.php,如下:

http://example.com/index.php/yyyy/mm/dd/post-name/

PATHINFO类型的连接无需复杂的操作就可以实现,在wordpress后台面板就可以设置,要想实现静态地址,在连接的最后添加.html即可。但是/index.php是不能去掉的,去掉就不河蟹了。

漂亮的连接是指自定义的不带index.php的固定连接,也就是把PATHINFO类型的链接地址的index.php去掉,但是,如果我们直接把index.php去掉,就会出现打开页面错误。解决方法很简单,自定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 );
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值