ds42774 2012-12-08 06:32
浏览 15

URL路由在非条件下

I want to call a specific module when url doesnot contail certain words. Eg.: if url is www.abc.com/articles/a, I want to route it normally. If url is www.abc.com, it should be calling default module. But if url is www.abc.com/qw/asw, it should call blog module (Controller).

  • 写回答

2条回答 默认 最新

  • dongxu1875 2012-12-08 06:49
    关注

    You can cut out and checked the url this way:

    $subdir  = substr(realpath(dirname(__FILE__)), strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
    $tmp_array = explode('?', trim($_SERVER['REQUEST_URI']));
    $uri = str_replace($subdir, '', $tmp_array[0]);
    $uri = ltrim($uri, '/');
    $URIParts = explode("/", $uri);
    
    
    $URIPartsCount = count($URIParts);
    
    if( $URIPartsCount>0 && in_array($URIParts[0],$pages) )
    {
        $uripart = $URIParts[0];
        if( in_array($uripart,$somearray) )
        {
            $page = $uripart;
        }
        ...
        else
        {
            $page = "index";
        }
    }
    else
    {
        $page = "index";
    }
    
    if( $URIPartsCount>1  )
    {
        $todo =  $URIParts[1];
    }
    else
    {
        $todo = "";
    }
    

    .htaccess

    RewriteEngine on  
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteRule ^(.*)$ index.php?q=$1 [QSA]  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?