dongsheng4126335 2013-06-22 23:24
浏览 46
已采纳

CodeIgniter URI路由URI段和htaccess

I'm facing a URI Routing problem that I'm sure someone here can help me solve. I've googled enough to make my brain freeze. Okay, here is the situation

CodeIgniter Version : 2.1.3

I've routed two pages in the application/config/routes.php

$route['sites/(:any)'] = 'profiles/professional';

$route['sites/(:any)/(:any)'] = 'profiles/professional/$1';

I've a controller named : Profiles

A Method inside Profiles :

public function professional(){

    $user = $this->uri->segment(3);

    $current_page = $this->uri->segment(4);

    switch ($current_page) {
        case 'about':
            $this->data['content'] = 'user_sites/about_view';
            break;
        default:
            $this->data['content'] = 'user_sites/home_view';
            break;
    }



    $this->load->view('my_view',$this->data);       
}

Now if I load

www.mysite.com/sites/some_user/

It loads just fine. And Routing works fine. (I've htaccess file to remove index.php )

But when I try to load

www.mysite.com/sites/some_user/about/

It wont load (blank page). However, the route is actually working. Because when I load

www.mysite.com/sites/index.php/some_user/about/

It loads using my switch in the controller.

So I think I've to add a line or two of code in my .htaccess file? Someone please help? My current .htaccess file looks like this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

ModRewrite is ON too.

Thanks a lot in advance...

  • 写回答

1条回答 默认 最新

  • dso0139 2013-06-23 20:26
    关注

    I think you got a mistake in your count of segments and Your codecs looking the about keyword in segment 4 so it will find it in this URL www.mysite.com/sites/index.php/some_user/about

    Note that here the index.php is not really the index page as it is after the sites controller and it is referring g to it as a segment (therefor it is not an htaccess. Issue)

    If you remove the index.php www.mysite.com/sites/some_user/about

    About is located in segment number 3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面