2013-06-22 91 views
0

我正在面對一個URI路由問題,我敢肯定這裏有人可以幫我解決。我的搜索引擎足夠讓我的大腦凍結。好吧,這裏的情況是CodeIgniter URI路由URI段和htaccess

笨版本:2.1.3

我在的application/config/routes.php文件

$路線[路由兩頁 '(:任何)網站/' ] ='profiles/professional';

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

我有一個名爲控制器:配置文件裏面配置文件

一種方法:

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);  
} 

現在,如果我加載

www.mysite.com/sites/some_user/

它加載得很好。路由工作正常。 (我htaccess文件刪除的index.php)

但是當我嘗試加載

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

它不會加載(空白頁)。但是,該路線實際上正在工作。因爲當我加載

www.mysite.com/sites/ 的index.php/some_user /約/

它加載使用我的開關控制器。

所以我認爲我必須在我的.htaccess文件中添加一行或兩行代碼?有人請幫忙?我當前的.htaccess文件看起來像這樣

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

ModRewrite也是ON。

感謝很多提前...

+0

嘗試回聲這樣:$ CURRENT_PAGE = $這個 - > URI->段(4)。你有什麼? – sinisake

+0

什麼都不顯示「www.mysite.com/sites/some_user/about/」 www.mysite.com/sites/index.php/some_user/about實際上顯示一切正常。所以我認爲它應該是一個.htaccess修復? – tintinboss

+0

有人嗎?有答案? – tintinboss

回答

1

我覺得你有你的段數和 你的編解碼器的錯誤尋找在段4的約關鍵字,因此會發現它在這個URL www.mysite .com/sites/index.php/some_user/about

請注意,這裏index.php並不是真正的索引頁面,因爲它位於sites控制器之後,並且它將它作爲段引用(因此它是不是htaccess。問題)

如果你刪除index.php www.mysit e.com/sites/some_user/about

關於位於段號3

+0

謝謝盧平!這解決了它!你的解釋也很完美。我現在明白了事實。希望這可以幫助別人。再次感謝:) – tintinboss