开发者

rewrite rule for codeigniter

this is my controller in CI

class Welcome extends Controller {

 function Welcome()
 {
  parent::Controller(); 
  }

 function index()
 {

 }
 function bil($model='')
 { }

I want to do a rewrite so that

http://example.com/index.php/welcome/bil/model

becomes

http://example.com/model

in my htaccess I have

RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
#RewriteRule ^(.*)$ /index.php/welcome/bil/$1 [L]

I thought it should be as easy as 开发者_运维知识库removing the /index.php/welcome/ part but when I uncomment the last line it get 500 internal server error


You'll want to use mod_rewrite to remove your index.php file like you have above, but use CodeIgniter's routing features to reroute example.com/model to example.com/welcome/bil/model.

In your routes.php configuration file, you can then define a new route like this:

// a URL with anything after example.com 
// will get remapped to the "welcome" class and the "bil" function, 
// passing the match as a variable
$route['(:any)'] = "welcome/bil/$1";

So then, typing example.com/abc123 would be equivalent to example.com/welcome/bil/abc123.

Note that only characters permitted by $config['permitted_uri_chars'] (which is located in your config.php file) are allowed in a URL.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜