I’m trying to make my CodeIgniter application work similarly to WordPress.

I want to be able to make these kind of URLs:

http://www.example.com/my-post-example

http://www.example.com/new-headline-here

http://www.example.com/i-love-stackoverflow

My routing:

$route['(:any)'] = "core/index/$1";

Which will call my Core controller and pass the page name into the index function.

I then lookup in my database for the page name and display the page to the user. So far so good.

However, there will be times when I want to call another controller. For example:

http://www.example.com/admin/edit_page/3

http://www.example.com/admin/settings

Now I assume my route will just grab all these rules and send them into my Core controller. Is there a way to make an exception for certain pages? Or is it a good idea to do this check inside my Core controller.

For example,

if ($page not in DB) {
   // Call controller/method
}

This seems a little redundant since I just want CodeIgniter to handle this.

Any suggestions?

Thanks!

Read more here: Routing in CodeIgniter for (:any)


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: