1

私は Codeigniter 2 を使用しています。バック オフィスから作成され、ページ名が ID である動的ページ (CMS) がいくつかあります。一部のページは静的です。例があります:

動的ページ:

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

および静的ページ:

www.domain.com/invitation

したがって、問題は、このページをどのようにルーティングできるかです:私は使用しようとしました:

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

しかし、静的ページの場合は 404 になります ( www.domain.com/invitation)

どんな助けでも、事前に感謝します

4

1 に答える 1

1

ファイルのリダイレクトから静的ファイルを明示的に削除でき.htaccessます。

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

または、_remap関数を使用できます。関数内_remapで、「メソッド」の物理ファイルの存在を確認します。存在する場合はロードし、存在しない場合はコントローラー メソッドにルーティングします。

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();
    }
}
于 2013-02-05T21:37:50.043 に答える