Nabil Lemsieh
Nabil Lemsieh

Reputation: 716

Dynamic CMS pages and static pages CodeIgniter

I'm using Codeigniter 2, and i have some dynamic pages (CMS) which are created from the back office and have the page name as ID . And some pages are static , there is a example :

Dynamic pages :

www.domain.com/privacy
www.domain.com/about

and static page :

www.domain.com/invitation

So the question is how can route this pages : i tried to use :

 $route['([a-z0-9\-]+)'] = 'home/cms/$1';

But it gives me 404 for static pages ( www.domain.com/invitation )

Any help and thank you in advance

Upvotes: 1

Views: 716

Answers (1)

swatkins
swatkins

Reputation: 13630

You can either explicitly remove the static files from the redirection in your .htaccess file:

RewriteEngine on
RewriteCond $1 !^(invitation\.php|index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

or, you can use the _remap function. Inside the _remap function, you would check for existence of a physical file for your "method" - if there, load it - if not, route to the controller method:

public function _remap($method, $params = array())
{
    $filepath = BASEPATH.$method.".php";
    if (file_exists($filepath))
    {
        include($filepath);
        return;
    }
    else if (method_exists($this, $method))
    {
        return call_user_func_array(array($this, $method), $params);
    }
    else
    {
        show_404();
    }
}

Upvotes: 1

Related Questions