• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to this url rewriting and loading other controllers?

I'm experimenting with codeigniter.

I like to have search engine friendly urls like this:
example.com/honda/accord or

where honda is the category and accord is the page.
I can do this easily with procedural programming like so:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

// I put some code here to explode the url and get it into segments.....
// so $category = honda and $page = accord
if(isset($page)) {
} elseif(isset($category)) {

based on the two urls above the first one would include page.php the second would include category.php
then the category.php page does whatever a category page does and the page.php page does whatever a page page does.

But with codeigniter I have the same .htaccess file and here is my index.php (welcome.php)

class Welcome extends Controller {

    function Welcome()
    function index()
        if(segment(1) && segment(2)) {
            //how do I include the category.php controller?
        } elseif(segment(1)) {
            //how do I include the page.php controller?

I understand I can use urls like:
And that will do exactly what I want ...
But I don't want the words category or page in the url. I want the urls that I showed above.

Any suggestions?
What about creating a new method so I can $this->load->controller('category.php'); // is that possible? or would that have side effects?

Messages In This Thread
Best way to this url rewriting and loading other controllers? - by El Forum - 01-07-2010, 09:43 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.