Welcome Guest, Not a member yet? Register   Sign In
Help with routes
#1

[eluser]louis w[/eluser]
This is what I have in my routes files:

Code:
$route['admin/(.*)']     = "admin/$1";
$route['(.*)']        = "page/$1";

I want my site to forward any requests besides ones to /admin/ANYTHING to the page controller.

/admin/ would go to /admin/
/about/ would go to /page/about/

etc.

The second part works, but if i go to /admin/ it does not forward to the admin controller. If i take off the two routes /admin does work.
#2

[eluser]mironcho[/eluser]
Hi Louis. This rule:
Code:
$route['admin/(.*)']     = "admin/$1";
means that admin/ANYTHING will redirect to admin/ANYTHING . But admin on it self won't. So you can add aditional rule:
Code:
$route['admin']     = "admin";
or replace both rules with one:
Code:
$route['([^(admin)]*)']        = "page/$1"
#3

[eluser]louis w[/eluser]
Thanks for the help. I can not get either to work. I tried

Code:
// Doesn't work
$route['admin/(.*)']    = "admin/$1";
$route['admin']         = "admin"
$route['(.*)']            = "page/$1";

and

Code:
// Doesn't work
$route['([^(admin)]*)']        = "page/$1"

Both sit there processing (i think it may be getting stuck in a redirect loop). It's not my site because the below works for non admin pages.
Code:
// Works for non admin pages
$route['(.*)']            = "page/$1";
#4

[eluser]mironcho[/eluser]
Any errors in apache/codeigniter log files (while processing)?
These rules work on my local test server (LAMP) with simple page and admin controllers.
#5

[eluser]louis w[/eluser]
What url's are you testing? Do you have a Page and Admin controller?

[Tue Apr 22 16:41:58 2008] [error] [client 127.0.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
#6

[eluser]mironcho[/eluser]
Here they are.
page.php:
Code:
<?php

class Page extends Controller {

        function Page()
        {
                parent::Controller();
        }

        function index()
        {
                echo 'page';
                $this->load->view('welcome_message');
        }

        function test()
        {
                echo 'page/test';
                $this->load->view('welcome_message');
        }

}
?>
and admin.php:
Code:
<?php

class Admin extends Controller {

        function Admin()
        {
                parent::Controller();
        }

        function index()
        {
                echo 'admin';
                $this->load->view('welcome_message');
        }

        function blabla()
        {
                echo 'admin/blabla';
                $this->load->view('welcome_message');
        }

}
?>
I've tested with admin, admin/blabla, test (which goes to page/test).
#7

[eluser]louis w[/eluser]
Ok, progress.

I made a whole new site to make sure there was nothing else conflicting. During this process I noticed that your original route was missing an ending ; I think this caused the loop problem.

I have it working with just your two bare bones except in one instance. If you type in /foo/bar it does not rewrite to page (/admin/bar does work).

Also, swap out both of your index methods for the below _remap one. I am using it to distribute the request.

Code:
function _remap() {
            echo 'HELLO This is page. The url is: '.$this->uri->uri_string();
    }
#8

[eluser]wiredesignz[/eluser]
Code:
$route['admin/(.*)']    = "admin/index/$1";
#9

[eluser]louis w[/eluser]
I am using a _remap, don't need index to be called.

[quote author="wiredesignz" date="1209004825"]
Code:
$route['admin/(.*)']    = "admin/index/$1";
[/quote]
#10

[eluser]mironcho[/eluser]
Sorry about missing semicolon (it's late night/early morning here).




Theme © iAndrew 2016 - Forum software by © MyBB