Welcome Guest, Not a member yet? Register   Sign In
How can i get this kind of urls
#1

[eluser]Eugen[/eluser]
Hi guys, i am stuck with this problem: How can i have urls like these:

Code:
mytld.com/europe
mytld.com/spain
mytld.com/barcelona
mytld.com/barcelona-aquarium

As you can see i do not want to use mytld.com/spain/barcelona/barcelona-aquarium

I want to have only one url segment witch can be a continent, a country, a city, or a point of interest...

How can i make a difference between them and redirect to the propper controller/view ???

Thanks for any suggestion or code sample you might post here!
#2

[eluser]kr1pt[/eluser]
Routes.
#3

[eluser]Eugen[/eluser]
I know about routes ... The question is what is the best approach to make a difference between a continent, a country, a city, or a point of interest… That one word or phrase can be anything: a continent, a country, a city, or a point of interest.
#4

[eluser]CroNiX[/eluser]
1) Prefix your url with the type of data it is, like ci-barcelona to indicate that barcelona is a city. Then create a route that starts with "ci-" and map it to a controller/method that handles cities. Then do the same for each type you have (country, etc). This would be most efficient for the app, but you have to give it something to go on to map it to the correct method.

or

2) If you don't want the prefixes, then the app will require more lifting to find the correct category that the request belongs to. Create a single catch-all route and have that controller search your db tables until it finds what it needs. This makes for much cleaner URLs, but the code is a lot more inefficient as it has nothing to go on, so it has to search through them all until it finds the correct one, or 404's if it doesn't. You could also create a single table that maps urls to what type they are to make this a bit faster. A lookup table.
#5

[eluser]aquary[/eluser]
Kind of off topic, but is it only me who like it better when the URL has its hierachy?....
#6

[eluser]Eugen[/eluser]
@CroNiX - Thanks for your ideas.

It is not that i like it that way, or it's better my way... But i will have really long urls, and i think it will be better for users and engines too with those short url...

Any other ideeas?
#7

[eluser]CroNiX[/eluser]
It's up to you how you do it. I'll just say that google has no problem cataloging segments at all. It's a lot better than query strings and they are in a logical, organized manner. As I say, you can do it with single urls, but it will not be as efficient and it will be harder to build/maintain. It will make CI harder to use as you are going against the default behavior and will now have to manually route everything. Still, it's possible. I personally wouldn't do it that way. It's fine for some pages, like an "about" page, but I just create special routes for my 'single url' pages and the rest use CI normally.




Theme © iAndrew 2016 - Forum software by © MyBB