2011-12-21 151 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