Welcome Guest, Not a member yet? Register   Sign In
URL Rewrite
#2

[eluser]mattpointblank[/eluser]
This is what routes.php inside your application/config/ folder. You can define regular expressions to forward your URLs like this:

Code:
$route['read/(:any)/(\d+)'] = "home/read/$2";

This code is pretty simple - the first part after the $route defines the URL you'd like users to see. The (:any) keyword simply means any combination of characters, eg. your novel title. The (\d+) means digit, so that's your chapter number.

In the other half of the statement is the method/controller you're using. The $2 refers to the second variable, eg the (\d+) or chapter number. In this example I've assumed your read() method only requires the chapter number, but if you need to pass it the name as well, just change it to "home/read/$1/$2". Make sense?

Bear in mind that when you start changing your routes, you may have to start manually adding everything. For example, if you wanted to remove /read/ from the URL altogether, you could do so using this method, but that would mean that every new controller/method you added would need to be manually added to routes.php as well, otherwise the wildcards will override it.


Messages In This Thread
URL Rewrite - by El Forum - 01-11-2010, 01:20 AM
URL Rewrite - by El Forum - 01-11-2010, 03:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB