• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need advice on SEO friendly URLs

#1
[eluser]zuluanshee[/eluser]
I'm building a travel site. People will access cities through a tree of sorts. I want to create urls that say
mytravelsite.com/Europe/France/Paris
mytravelsite.com/Europe/Italy/Rome
mytravelsite.com/Asia/China/Beijing

I'm doing this in part because I want to implement breadcrumbs.

My question: is mod_rewrite the only way to do this? There will be a lot of cities. In fact, I've found a list of every city in the world and plan on building a database Smile

I'm afraid i know so little about mod_rewrite, I don't know if this can even be done easily. Does every single city have to be mapped in .htaccess? My city list has about 250,000 cities in it. Or, is there a 'built-in' way to do this with CI?

thanks

#2
[eluser]brianw1975[/eluser]
I wouldn't even use mod_rewrite....

read http://ciuserguide/general/routing.html

Code:
$route['([A-Za-z]+)/([A-Za-z]+)/([A-Za-z]+)'] = "region/$1/country/$2/city/$3";
of course region is the controller, country is the function and city is the var
Code:
function city($cityname){};

I think that should (read: might?) be able to do your routing.

I never was very good at RegEx...

of course you will want to put in checks for valid entries, and some modifications for city and country names with spaces, etc.

#3
[eluser]zuluanshee[/eluser]
ill give it a try tomorrow and let you know. Thanks.

#4
[eluser]brianw1975[/eluser]
actually, looking at that again... that won't work at all..... not sure what I was thinking at the time....my only excuse is being stuck in session purgatory...

hopefully someone else can chime in

#5
[eluser]aquary[/eluser]
You are having the same problem I had before. I asked in the forums and some guy came up with this solution.

I don't have the actual codes now, but it looks like these:

Code:
$route['(:any)/(:any)/(:any)'] = "location/city/$3";
$route['(:any)/(:any)'] = "location/country/$2";
$route['(:any)'] = "location/continent/$1";

Now, that solved the problem, but a new problem arise. All of the link will go to "location" controller, so you have to put more routing rules for all others controllers.

Code:
$route['contact'] = "contact/default";
$route['contact/(:any)'] = "contact/$1";
$route['articles'] = "articles/default";
$route['articles/(:any)'] = "articles/$1";
$route['(:any)/(:any)/(:any)'] = "location/city/$3";
$route['(:any)/(:any)'] = "location/country/$2";
$route['(:any)'] = "location/continent/$1";

#6
[eluser]John_Betong[/eluser]
 
I have problems with routing and mod_rewrite so I would go for this simple(?) solution

Because there are only five continents then have a controller for each continent.

1. NOT REQUIRED: // Each controller inherits a common MY_Controller
2. the index function is passed two variables, $country and $city.
3. these two parameters are used to query a database table
4. the results are passed to a common view function.

Code:
<?php

class Asia extends Controller /* MY_Common_Controller NOT REQUIRED */
{
//==============================================================    
//
// The Asia controller
//   usage:
//       http://mytravelsite.com/Asia/Thailand/Bangkok
//
//==============================================================    
function index($country='', $city='')
{
   $view_file = 'the_home_page';  // default to no parameters
   if ('' != $country) // Yes we have a country
   {
      $data      = $this->my_model->Please_can_I_have_details_for('Asia', $country, $city);
      $view_file = 'this_holiday';  
    }
    $this->show_me_the_view_for($view_file, $data);

}//endfunc

}//endclass
 
 
 
edit: removed MY_Common_Controller, added Home page is no parameters passed.
N.B. Please note this code has not been tried and tested.
 
 
 

#7
[eluser]garycocs[/eluser]
Any chance you'd like to share the DB of cities?? Big Grin

#8
[eluser]Johan André[/eluser]
There are complete databases of cities (with zipcodes, areacodes, longitude, latitude etc) to buy...

I bought one with all swedish zipcodes, cities, municipals etc.

#9
[eluser]zuluanshee[/eluser]
You can get a zip of all the cities in teh world here:

http://www.maxmind.com/download/worldcit...pop.txt.gz

caveat: the country is in two letter code. And some countries like England and Wales are listed under GB. You'll have to finagle it to get it right.

#10
[eluser]garycocs[/eluser]
In fact ah nice one!!!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme ¬© 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.