大家经常看到别的站的URL是这样的吧?http://www.xxx.com/module/show/action/list/page/7
或者http://xx.com/module/show/action/show/id/8.shtml 带扩展名的
或者http://xx.com/module/show/action/show/id/8?word=ss&age=11
这样的吧
今天我就是公布下这种方法的实现,并独立出最简单的代码函数如下,没封装成类,主要是没必要,用函数能方便些
* 获得友好的URL访问
*
* @access public
* @return array
*/
function getQueryString(){
$_SGETS = explode(“/”,substr($_SERVER[‘PATH_INFO’],1));
$_SLEN = count($_SGETS);
$_SGET = $_GET;
for($i=0;$i<$_SLEN;$i+=2){
if(!empty($_SGETS[$i]) && !empty($_SGETS[$i+1])) $_SGET[$_SGETS[$i]]=$_SGETS[$i+1];
} $_SGET[‘m’] = !empty($_SGET[‘m’]) && is_string($_SGET[‘m’]) ? trim($_SGET[‘m’]).‘Action’ : ‘indexAction’;
$_SGET[‘a’] = !empty($_SGET[‘a’]) && is_string($_SGET[‘a’]) ? trim($_SGET[‘a’]) : ‘run’;
return $_SGET;
}
/**
* 生成链接URL
*
* @access public
* @param array $arr
* @return string
*/
function setUrl($arr){
global $Global;
$queryString=”;
if($Global[‘urlmode’]==2){
foreach($arr as $k=> $v){
$queryString.=$k.‘/’.$v.‘/’;
}
}
$queryString.=$Global[‘urlsuffix’];
return $queryString;
}
?>
?>
RewriteEngine on
RewriteCond $1 !^(index\.php|css|pics|themes|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]现在OK了,赶快去测试吧
print_r($_GET);
?>
原创文章,作者:键盘游走者,如若转载,请注明出处:https://www.708034.com/2008/05/%e5%8f%8b%e5%a5%bdurl%e7%9a%84%e5%ae%9e%e7%8e%b0/