Welcome Guest, Not a member yet? Register   Sign In
Routing to specific controller if class doesn't exist?
#1

[eluser]Unknown[/eluser]
I swear I had this figured out at one point but I haven't been able to find my notes on it since I took a couple months off the project.

The plan is to have a club based site, and I want them to be able to make simple URL's to use so its easy to share and find their specific club on the site, sort of like Facebook does with business pages like: www.thesite.com/theclub which will show the clubs default home page by redirecting to www.thesite.com/home/theclub.

It would check for the class first, then if no class run the default homepage class and if "theclub" doesn't exists, it would show a 404 type page with some "hey dumb dumb... no clubs named theclub exist" message.

I was thinking htaccess would be the cleanest way, but for the life of me can't find a thread on it and I know saw one previously!

Thanks!
#2

[eluser]Unknown[/eluser]
I figured it out because of course as soon as I posted it I remembered the term for it haha!

Code:
$url_parts = explode('/',  strtolower($_SERVER['REQUEST_URI']));


$reserved_routes = array("club", "login", "profile", "welcome","home");
if (!in_array($url_parts[2], $reserved_routes)) {    
    $route['([a-zA-Z0-9_-]+)'] = "home/view/$1";
}




Theme © iAndrew 2016 - Forum software by © MyBB