Welcome Guest, Not a member yet? Register   Sign In
Rewrite my urls in automatic and correct way
#1

[eluser]jparent[/eluser]
Hi. I want to rewrite my urls in the this way:

I have this:
http://wwww.myurl.com/news/categoryid/perpage

I want this:
http://wwww.myurl.com/news/categoryname

In other way I have this:
http://wwww.myurl.com/news/new/newid

And I want this:
http://wwww.myurl.com/new/name-of-the-new

How can I do that? Could anybody give me a clear example? Thank you very much.
#2

[eluser]Jeroen Brussich[/eluser]
Trying to understand your examples, I think you pull 'category' and 'id' from a database?
If so, pull the 'name' instead of the 'id' from the db and put that in the title.
#3

[eluser]jparent[/eluser]
sorry, I'll try to explain it better:

I have this:
http://wwww.myurl.com/controller/method/param1/param2

in my case:
http://wwww.myurl.com/news/categories/ca...id/perpage

and I want this:
http://wwww.myurl.com/news/categoryname

I need to pass id to the method because maybe two categories with the same name and different id.
I need to change the url with the routes archive or with code.

In other way I have this:
http://wwww.myurl.com/news/new/newid

And I want this:
http://wwww.myurl.com/new/title-of-the-new

The title in the database is like "title of the new". I need to change it to friendly url like "title-of-the-new"

I hope now its more clear. Thanks for your help.
#4

[eluser]rogierb[/eluser]
You have to create a slug that you store in the database next to the id and name.
Just make sure you slug is unique. If you set an index on the slug-field you can get the record using the slug.
#5

[eluser]jparent[/eluser]
Thank you very much. But, could you write an example? I don't understand clearly your explanation, maybe cause my poor english. Sorry.

I understand that when you put a record in the database you have a field called, for example "slug", that have "the-name-without-spaces", and that is the identifier of the record and I use that instead the numeric Id. Isn`t it?




Theme © iAndrew 2016 - Forum software by © MyBB