友好URL的实现

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
大家经常看到别的站的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
这样的吧

<?php

/**
* 获得友好的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;
}
?>
使用很简单
<?php
$_GET= getQueryString();
?>
但是这样还不行,这样只能实现

http://www.xxx.com/index.php/module/show/action/list/page/7 这样的

中间多了个index.php 为此我们要把他去掉,只好重写

但是有些文件 又不希望这样,比如 样式 图片,那就放条件里

建立一个 .htaccess文件


RewriteEngine on
RewriteCond $1 !^(index/.php|css|pics|themes|js|robots/.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
<?php
$_GET= getQueryString();
print_r($_GET);
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值