比如:http://localhost/index.php?q=main/index&cid=1&tid=2
重写为 http://localhost/index.php/q/main-index/cid/1/tid/2
这样可以吗?或者是有什么更好的建议吗?请高手指教,小弟是才开始学习PHP,谢谢大家了

解决方案 »

  1.   

    不知道你正则怎么样   配置apache   我的习惯是在  / 下 写个 .htaccess 例如 RewriteRule (products|cpzl)_(.+?)_(.*).html$ index.php?mod=$1&act=$2&var=$3
      

  2.   

    可以使用楼上的做法,对不对的自己去调试
    也可以使用PHP本身去实现。写一段PHP程序就可以了。
    <?php
    $queryString=$_SERVER['QUERY_STRING'];
    $queryArray=explode('/');
    foreach($queryArray as $val){
        $tempQueryArray=explode('-',$val);
        $_GET[$tempQueryArray[0]]=$tempQueryArray[1];
    }
    ?>
    这样的话应该就可以了,我临时写的,可能有错,楼主自己调试一下。
    重写前:http://<servername>/index.php?a=1&b=2
    重写后:http://<servername>/index.php/a-1/b-2
      

  3.   

    呵呵一下就看到了错误
    第二行代码:$queryArray=explode('/',$queryString);
      

  4.   


    $sURL = 'http://localhost/index.php?q=main/index&cid=1&tid=2';
    $sBeforeQuery = substr($sURL, 0, stripos($sURL, '?'));
    $sAfterQuery = substr($sURL, stripos($sURL, '?'));
    $sAfterQuery = str_ireplace('/', '-', $sAfterQuery);
    $sAfterQuery = str_ireplace(array('?', '=', '&'), array('/', '/', '/'), $sAfterQuery);
    $sURL = $sBeforeQuery . $sAfterQuery;
    echo $sURL;
      

  5.   

    没错,两种做法。一种是开apache的mod_rewrite进行重写。
    另一种是自己定义url规则,然后按照自己的规则解析url。
      

  6.   

    我rewrite
    iis的和apache的差不多
      

  7.   

    楼主要开发框架?
    这URL就是框架的默认URL了