Home  >  Article  >  Backend Development  >  php快速url重写 更新版[需php 5.30以上]_PHP

php快速url重写 更新版[需php 5.30以上]_PHP

WBOY
WBOYOriginal
2016-06-01 12:19:54802browse

对于apache的rewrite模块打开和设置则非本文主题,请见其他文章详解.
这个类只能php 5.30以上的版本才能使用,继承了上一个版本的快速重定向的特点(单独类,全部使用静态调用),增添了一个很重要的功能和属性 可以调用其他url中的模块了 也使得模块与模块间或页面与页面间的函数简化共享得以实现
.htaccess文件写法:
复制代码 代码如下:
#-------------- .htaccess start ---------------
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|htm|txt)$ index.php
php_flag magic_quotes_gpc off
php_flag register_globals off
#-------------- .htaccess end ---------------

重写功能引入:让站点根目录的index.php末尾写上下列代码,重写就开启了(正常条件:1.apache的重写配置成功,且开启了.htaccess支持的.2.站点根目录的.htaccess文件设置好了.3.class.rewrite.php类文件在index.php前面部分加载了.4.页面模块文件位置及写法无误):
复制代码 代码如下:
//............
Rewrite::__config(
$config['path'],/*'http://xxxxx/mysite/'URL基础位置*/
$config['md_path'],/*'c:/phpsite/www/mysite/modules/'模块文件物理目录*/
array(
'phpinfo'
)
);
Rewrite::__parse();
//..........

模块文件写法:
testPk.php
复制代码 代码如下:
class Rw_testPk extends Rewrite {
//这个是前导函数,只要访问到testpk这个页面,这个必然会执行,可用来控制本页面内函数访问权限或本页面全局变量
public static function init(){
//if (!defined('SITE_PASS')){
echo self::$linktag.'
';//self::$linktag是页面解析位置路径值,会常使用.
/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn