2011-06-02 48 views
1

我怎麼可以重寫以下網址笨重寫URL的笨

localhost/users/show_profile/john 

localhost/john 

感謝

回答

2

$route['(:any)'] = "users/show_profile/$1";
更多信息,你可以使用CodeIgniter Routes實現動態URL。

假設 localhost/users/show_profile/john

我們正在尋找:

localhost/controller/method/variable 

,我們可以使用下面的路線:

$route['([a-zA-z_]+)'] = "users/show_profile/$1"; 

你可以通過調用$this->uri->segment(1);內show_profile訪問變量()功能。

重要提示:$route['([a-zA-z_]+)']保留在routes.php文件末尾,以確保它不覆蓋任何其他路由。

0

config/routes.php加航線上here

+0

我不會使用(:任何),因爲它是貪婪的。我會看看正則表達式路線。 – tpae 2011-06-03 14:42:04