Codeigniter和RewriteRule问题

时间:2011-05-27 07:41:54

标签: apache .htaccess codeigniter

我一直困惑于此。这是我目前所做的重写规则:

Options +FollowSymlinks
DirectoryIndex index.php

RewriteEngine on
RewriteRule ^ext\/(.*)$ index.php/cproposal/key/$1 [NC]

基本上我想要

http://localhost/cvc/ext/12445345346

重写为

http://localhost/cvc/index.php/cproposal/key/12445345346

然而,Codeigniter正在制作404。如果我将规则的index.php/cproposal/key/$1部分更改为像目录中找到的Codeigniter license.txt那样的内容,那么它可以工作,但实际上与Codeigniter本身相关的任何内容都会产生404。

我出错的任何想法?

1 个答案:

答案 0 :(得分:2)

mod_rewrite很棒,但Codeigniter已经为您的Codeigniter应用程序中的任何内容提供了built in solution

尝试将此添加到您的config/routes.php

$route['ext/(:num)'] = 'cproposal/key/$1';

这将路由请求:

  

http://localhost/cvc/ext/{any_number}

  

http://localhost/cvc/cproposal/key/{requested_number}

index.php将是可选的,具体取决于您的CI配置。换句话说,如果你已经使用它 - 它将在网址中。如果没有,则不必如此。

除了内置的通配符(:num)(:any)之外,所有CI路由都可以使用正则表达式,因此您可以随意获得创意。