Welcome Guest, Not a member yet? Register   Sign In
Friendly URL Rewriting
#1

Hi,
For the moment my url's are :
Code:
http://website.fr/game/ID/name-of-my-game
I would like to have this kind of URL :
Code:
http://website.fr/game/name-of-my-game

How can i do that ?
My links are create like that :
Code:
<?=base_url().'game/'.$game->id.'/'.url_title($game->titlePost)?>

Is it possible to redirect on 404 error when someone change the url  
Code:
http://website.fr/game/name-of-my-game
by  
Code:
http://website.fr/game/name-of-m
Reply
#2

I wonder what your controller Game looks like.
Does it have a function (method) called ID?
Or is ID a parameter, just like the name of the game?
Reply
#3

(This post was last modified: 05-04-2015, 11:21 AM by CroNiX.)

In the controller's method where you are passing the name of the game, you'd just check the db to see if "name-of-my-game" existed, and if not do a show_404(). So it will only display something if it exists, so if someone entered "name-of-m" it would 404 since it doesn't exist.
Reply
#4

(05-04-2015, 11:10 AM)Wouter60 Wrote: I wonder what your controller Game looks like.
Does it have a function (method) called ID?
Or is ID a parameter, just like the name of the game?

It's an ID parameter Smile public function game($id = "")
Reply
#5

(05-04-2015, 11:20 AM)CroNiX Wrote: In the controller's method where you are passing the name of the game, you'd just check the db to see if "name-of-my-game" existed, and if not do a show_404(). So it will only display something if it exists, so if someone entered "name-of-m" it would 404 since it doesn't exist.

Oh can i do that for changing url and how can i link the name of the game and the id ?
name-of-game2 = id2
Reply
#6

You can get the ID by the name.

In your database the table game should looks like :
id | system_name | human_name

The record :
2 | name-of-game | Name of game

In your controller add a method that will search after the uri segment in your database, if the uri match the system_name you can return all data, if not you can display a 404 error page. Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB