CodeIgniter Forums
mange routes with htaccess file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: mange routes with htaccess file (/showthread.php?tid=56262)



mange routes with htaccess file - El Forum - 12-06-2012

[eluser]YahyaKACEM[/eluser]
hi, i have this content in my routes file :
Code:
$route['logout']    = 'admin/logout';
$route['res_yass']    = 'page/index/res_yass';
$route['res_nesr']    = 'page/index/res_nesr';
$route['societe']    = 'page/index/societe';
$route['app_type']    = 'page/index/app_type';
$route['future_plan_situation'] = 'page/index/future_plan_situation';
$route['plan_situation']          = 'page/index/plan_situation';
$route['fini_stand']   = 'page/index/fini_stand';
$route['future_app_type']  = 'page/index/future_app_type';
that works fine now but whenever i want to add a page i have to add it in the routes page and that's not a good idea. so how can i change it in a htaccess file except the logout one.
thanx in advance.


mange routes with htaccess file - El Forum - 12-06-2012

[eluser]Aken[/eluser]
Code:
$route['(:any)'] = 'page/index/$1';

No need for .htaccess - just use the :any wildcard and a back reference (parentheses).


mange routes with htaccess file - El Forum - 12-06-2012

[eluser]YahyaKACEM[/eluser]
[quote author="Aken" date="1354792716"]
Code:
$route['(:any)'] = 'page/index/$1';

No need for .htaccess - just use the :any wildcard and a back reference (parentheses).[/quote]
i already tried that but my full routes file is like this
Code:
$route['default_controller'] = "welcome";
$route['404_override']   = '';
$route['logout']    = 'admin/logout';
$route['res_yass']    = 'page/index/res_yass';
$route['res_nesr']    = 'page/index/res_nesr';
$route['societe']    = 'page/index/societe';
$route['app_type']    = 'page/index/app_type';
$route['future_plan_situation'] = 'page/index/future_plan_situation';
$route['plan_situation']  = 'page/index/plan_situation';
$route['fini_stand']   = 'page/index/fini_stand';
$route['future_app_type']  = 'page/index/future_app_type';

and i did this:
Code:
$route['default_controller']  = "welcome";
$route['404_override']   = '';
$route['logout']    = 'admin/logout';
$route['contact']    = 'contact';
$route['(:any)']    = 'page/index/$1';

but that didn't work when i go to contact i get an error about can't find page/index.


mange routes with htaccess file - El Forum - 12-06-2012

[eluser]CroNiX[/eluser]
Does it look something like this?

Code:
class Page extends CI_Controller {

  function __construct()
  {
    parent::__construct();
  }

  public function index($file = '')  //$file is what your route will pass to this method as the $1
  {
    if ($file === '')
    {
      echo 'No File Selected to Display';  //or show 404 error
    }    
    else
    {
      //check if file exists...display...etc.  If not, show 404 error
    }
  }
}