程序名称:Url Rewriter
开发者/组织名称:Cesar D. Rodas
运行环境:php+mysql,php+文本
官方网站:http://www.thyphp.com/
文章来源:http://www.OSphp.com.cn
下载地址:
请下载附件中的源码,不要直接复制 (已下载 1024 次)
程序介绍:
This class can be used to redirect requests based on URL rewriting rules.
It can check whether the current request URL matches one or more rules.
If one of the defined rules is matched, the class determines the path of a PHP script that will handle the request and executes that script using the PHP require command.
If none of the rules matches, the class include the default error script and returns the 404 status code to the browser.
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
在
中查看更多“Url Rewriter URL重写”相关内容
最后编辑: shuguang 编辑于2007/12/08 08:49
开发者/组织名称:Cesar D. Rodas
运行环境:php+mysql,php+文本
官方网站:http://www.thyphp.com/
文章来源:http://www.OSphp.com.cn
下载地址:
请下载附件中的源码,不要直接复制 (已下载 1024 次)程序介绍:
//oSPHP.COM.CN
This class can be used to redirect requests based on URL rewriting rules.
It can check whether the current request URL matches one or more rules.
If one of the defined rules is matched, the class determines the path of a PHP script that will handle the request and executes that script using the PHP require command.
If none of the rules matches, the class include the default error script and returns the 404 status code to the browser.

URL Rewriter
Cesar D. Rodas <cesar@sixdegrees.com>
This class provides an easy mechanism to manage URL rewriting, avoiding to write and manage the ".htaccess" file.
Another issue is that you can use a personalized regular expression for create friendlies URL.
//OsPHP.COM.CN
I. Basic Structure
<?php
require "url_rewriter.php";
$url = new url_rewriter('example/');
$url->e404 = "error.php";
// regular expression rules goes here
//开源代码OSPhP.COm.CN
$url->execute();
?>
II. Regular Expressions
The regular expression are simple a set of constants, variable, and optionals parts.
Example:
$country=array('Argentina','Brasil','Paraguay');
$url->add_rule("index.php","/[country]/{index.html}", array('country'=> $country) );
If the first rule give true, "index.php" will be executed. For that country must be "Argentina", "Brasil" or "Paraguay" (this is because we force with the third parameter. "Country" must be in $country), and must exist an "index.html" or nothing.
//PHP开源代码
* /Paraguay/index.html : Match
* /Paraguay/ : Match
* /Paraguay/foo.html : Mismatch
The :numberX, where X is an identification, variable is an special variable that it must be numeric for match.
Example:
$country=array('Argentina','Brasil','Paraguay');
$url->add_rule("foo.php","/[country]/[str]-[:number1]-site{-[:number2]}.[ext]", array('country'=> $country,':number2' => 2) );
//开源代码OSPhP.COm.CN
* /Paraguay/some_string-123-site.html : Match
* /Paraguay/some_other_string-123-site-456.html : Mismatch
* /Paraguay/some_other_string-123-site-2.html : Match
* /Paraguay/some_other_string-123-site-foo.html : Mismatch
III. Real life example
Steps for translate a page which is "foo.php?id=45" to its URL friendly mode.
//OSPHP.COM.Cn开源
* Download http://cesars.users.phpclasses.org/url_rewriter
* Edit url_handler.php
* Add a new rule
$url->add_rule("foo.php","/entry-[:number1].html");
* Change all your links
foo.php?id=45 for /entry-45.html
* Edit foo.php adding an extra header
<?php
$id = $urlVars['number1'];
//开源代码OSPhP.COm.CN
//check if $id exist
if ($id not exist) $urlHandler->error404();
//handle request as you did before
?>
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容
中查看更多“Url Rewriter URL重写”相关内容最后编辑: shuguang 编辑于2007/12/08 08:49
calvin_shen
2008/11/14 13:37
wo,learning!!!
分页: 1/1
1
1



















