views:

43

answers:

3

I am looking to use a URL shortening scheme where I would like the variable to be in the first segment of the URL, www.example.com/0jf08h204. My default controller is "home.php" and I have .htaccess mod-rewrites in place, so what is the best way to manage this? I suppose my smarts have been blocked by the standard /controller/method/variable scheme, is this a URI Protocol setting? Thank you!

A: 

I myself haven't played a whole lot with Routing, but I think you could try something like this:

$route['(:any)'] = "controllername/actionname/$1";

Haven't tried this myself though.

Matthew
+1  A: 

To add to Matthew's response.

This is what you'll need in your system/application/config/routes.php file:

$route['(:any)'] = "home";

This will redirect EVERYTHING.

You might not want to redirect everything if you have other controllers which you need to use. If that is the case you can use this regular expression instead:

$route['^(?!about|contact)\S*'] = "home";

This will allow you to redirect everything except the controllers 'about' or 'contact' -- these will be directed to the 'about.php' and 'contact.php' controllers.

Please note, I choose not to use the wild cards within CodeIgniter, you might find they work better for you, I however choose to parse out the $_SERVER['REQUEST_URI'] manually after the redirect. If however you wanted to use the wildcards you would just add /$1 to the routes as you see in Matthew's response.

evolve
A: 
Prime Studios
404's should be handled right in the controller, if you can't find a shortened URL that matches the URL submitted, then return a 404.
evolve
Yeaa, adding a validation step helped clean this up.. Thank you.
Prime Studios