代碼如下:
#
RewriteEngine on
RewriteRule !
php_flag magic_quotes_gpc off
php_flag register_globals off
#
重寫功能引入:讓站點根目錄的index
代碼如下:
//
Rewrite::__config(
$config[
$config[
array(
)
);
Rewrite::__parse();
//
模塊文件寫法:
testPk
代碼如下:
<?php
class Rw_testPk extends Rewrite {
//這個是前導函數
public static function init(){
//if (!defined(
echo self::$linktag
//}
}
//當訪問"時會執行
public static function index(){
echo
}
//當訪問"時會執行或寫作"一般"index/"都是可以被省略的
public static function blank(){}
}
?>
class
代碼如下:
<?php
class Rewrite{
public static $debug = false;//是否打開調試
public static $time_pass =
public static $version =
public static $pretag =
public static $linktag =
protected static $time_start =
protected static $time_end =
protected static $physical_path =
protected static $website_path =
protected static $ob_contents =
protected static $uid =
//允許的系統函數如$allow_sys_fun=array(
private static $allow_sys_fun = array();
private static function __get_microtime(){
list($usec
return ((float)$usec + (float)$sec);
}
//設置調試Rewrite::__debug(true);
public static function __debug($d = true){
static::$debug = $d;
}
//配置路徑和允許函數
public static function __config($website_path =
self::$physical_path = $physical_path;
self::$website_path = $website_path;
self::$allow_sys_fun = $allow_sys_fun;
}
//調試函數
public static function __msg($str){
if(static::$debug){
echo "n<pre>n"
}
}
//解析開始時間
public static function __start(){
self::$time_start = self::__get_microtime();
}
//解析結束時間
public static function __end($re = false){
self::$time_end = self::__get_microtime();
self::$time_pass = round((self::$time_end
if($re){
return self::$time_pass;
}else{
self::__msg(
}
}
//內部跨模塊url解析調用
public static function __parseurl($url =
if(!empty($url)&&!empty($fun)){
$p = static::$physical_path;
if(file_exists($p
$part = strtolower(basename( $p
static::$linktag = $part
$fname = static::$pretag
if(class_exists($fname
if(method_exists($fname
return $fname::$fun($data);
}
}else{
include( $p
if( class_exists($fname
return $fname::$fun($data);
}
}
}
}
}
//核心鏈接解析函數Rwrite::__parse();在頂級重寫核心定向目標index
public static function __parse($Url =
self::__start();
$p = static::$physical_path;
$w = static::$website_path;
$req_execute = false;
$url_p = empty($Url) ? $_SERVER[
$local = parse_url($w);
$req = parse_url($url_p);
$req_path = preg_replace(
$req_para = empty($Url) ? strstr($_SERVER[
if(empty($Url) && substr_count($_SERVER[
self::__goto($req_para
return ;
}else{
$req_path_arr = empty($req_path)?array():preg_split("|[/]+|"
$req_fun = array_pop($req_path_arr);
if(substr($req_fun
$req_fun = substr($req_fun
}
$req_path_rearr = array_filter($req_path_arr);
self::__msg($req_path_rearr);
$req_temp = implode(
$fname = $req_temp
if(!empty($req_fun)&&in_array($req_fun
$req_fun();
}else{
if(!empty($req_fun)&&file_exists($p
include( $p
}else{
$fname = empty($req_temp) ?
if(file_exists($p
include( $p
}else{
$fname = $req_temp
if(file_exists($p
include( $p
}else{
//這個地方是對"個人主頁"的這種特殊鏈接定向到"profile/"了
//如:www
$uid = is_numeric($req_temp) ? $req_temp : strstr($req_temp
$ufun = is_numeric($req_temp) ?
if(is_numeric($uid)){
self::$uid = $uid;
if(!isset($_GET[
$fname =
if(file_exists($p
include( $p
}else{
header("location:"
exit();
}
}else if(file_exists($p
$fname =
include( $p
}else{
header("location:"
exit();
}
}
}
}
$ev_fname = strrpos($fname
$ev_fname = static::$pretag
if( class_exists($ev_fname
static::$linktag = $req_fun==
if($req_fun !=
$ev_fname::init();
}
$ev_fname::$req_fun();
}else if( class_exists($ev_fname
static::$linktag = $fname
if(method_exists($ev_fname
$ev_fname::init();
}
$ev_fname::index();
}else if( $fname !=
$ev_fname = static::$pretag
static::$linktag =
if(method_exists($ev_fname
$ev_fname::init();
}
$ev_fname::index();
}else{
self::__msg(
}
}
}
self::__end();
}
//這裡是用戶自定義鏈接的解析(用數據庫存儲的解析值) 如: xiaoming
//數據庫中 xiaoming這個標簽指向一個人的博客 就會到了www
public static function __goto($para =
$w = static::$website_path;
if(empty($para)){
exit(
}
if(class_exists(
$prs = Parseurl::selectone(array(
self::__msg($prs);
if(!empty($prs)){
$parastr = $prs[
$output = array();
$_GET[$prs[
parse_str($prs[
$_GET = array_merge($_GET
$path = $prs[
self::__msg($path);
header(
exit();
}else{
header("location:"
exit();
}
}else{
header("location:"
exit();
}
}
}
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/20859.html