Welcome Guest, Not a member yet? Register   Sign In
Default controller routing
#1

[eluser]JanDoToDo[/eluser]
Hey guys,

I'm net at Codeigniter so this might be a very basic thing but - If I go to my site with no controller it loads the default controller and default function but doesnt append this to the URL. If I wanted to load another function from the default controller apart from the default function I would have to use the URL mydomain.com/home/function.

My question is, how would i rewrite it (htaccess?) so that the default controller is automatically apended to the URL if none is provided so that when it goes to home/function it doesnt go from a URL with no segments to a URL with 2 segments (as i think it looks a bit messy). Alternatively, is there anyway to tell CI to look for a function name in the default controller the same as the segment string instead of looking for a controller by that name. So:

domain.com, points to domain.com/home
can this be changed so that, either:
domain.com is rewritten as domain.com/home OR
domain.com/seg1 where seg1 is actually a function in the home controller and CI looks for this before it looks for a controller called seg1


Many thanks!
#2

[eluser]BrianDHall[/eluser]
First, as to domain.com being rewritten to domain.com/home, I think you mean that you want that URL to actually show in the browser? Routes don't do that, regardless of how it is accomplished you would be issuing a redirect to the browser that "this address isn't what you want, what you really want is THIS address".

I think in your default controllers constructor you can just create a route to check to see if there are no segments, and if not issue a redirect() that points them to what the address you want them to use is.

As to getting domain.com/seg1 to submit seg1 as a parameter to a controller, yes you can do that as well but typically the problem is you tend to lock yourself into using one controller or having to create manual exclusions for certain controllers, and then introducing name conflict possiblities as well. I've done it, but I don't really recommend it.

You just create a route that takes everything and rewrites it to your default controller, with everything captured stuck as a parameter.




Theme © iAndrew 2016 - Forum software by © MyBB