views:

47

answers:

1

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

A: 

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!

Colin