2011-12-21 62 views
0

我想重寫一個CodeIgniter應用程序的URL,雖然它似乎沒有工作。 我有以下的事情設置;CodeIgniter URL重寫

$route['pages/(:num)/(:any)'] = "pages/view/$1/$2"; 
$config['index_page'] = ''; 

然後我有以下.htaccess;

RewriteEngine on 
RewriteBase/

RewriteRule ^pages/(.*)/(.*)$ /index.php/pages/view/$1/$2 [L] 

它只是說沒有找到該頁面(Apache錯誤,而不是CodeIgniter)。 它在我瀏覽到原始鏈接(http://domain.tld/index.php/pages/view/1/welcome)時有效,但在瀏覽到「所需」鏈接時不起作用(http://domain.tld/頁/ 1 /歡迎)。

我在做什麼錯?

+0

我認爲你需要有htaccess的從URL中刪除index.php文件,它應該工作 – 2011-12-21 10:01:55

+0

不完全是,它不只是去掉「的index.php」,但也方法的名稱;視圖。 – Roel 2011-12-21 10:04:06

+0

你檢查過Apache日誌,找出Apache是​​改寫這?此外,您可能需要$ 1的非貪婪版本的匹配,即'^ pages /(.*?)/(.*)$' – 2011-12-21 10:14:02

回答

1

嘗試:

 
$route["pages/(.*)/(.*)"] = "pages/view/$1/$2"; 
//and your htacess, remove your current rule and 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

。謝謝。 – Roel 2011-12-21 10:21:39

1

難道是你在你的RewriteRule中丟失了?

# Substitute " >>?<< " with "?". It's there to point you to the change. 
RewriteRule ^pages/(.*)/(.*)$ /index.php >>?<< /pages/view/$1/$2 [L] 
+0

不是這樣,Codeigniter使用斜線格式,加上手動使用重寫版本的op狀態,可以使用 – 2011-12-21 10:14:34