Welcome Guest, Not a member yet? Register   Sign In
Transforming codeigniter URLs to SEO friendly URLS
#1

[eluser]Saints77[/eluser]
My apologies if this has been answered somewhere else but I cannot find a solution to this problem.

I'm looking to create URL's such as this: world-travel-locations instead of using the codeigniter controller/method style links: gallery/locations

I can do this very easily in a non-MVC style approach but being now to CodeIgniter I have no idea how to achieve this.

I've tried configuring my routes.php file in the following manner:

$route['world-travel-locations'] = "gallery/locations";

I thought this would be the best way to achieve the above but no joy whatsoever.
I've looked over the codeIgniter documentation and don't find it very useful in explaining how to achieve the above.

How easy is it to achieve a keyword rich, SEO friendly url with codeIgniter rather than the default controller/method naming style?

Do I have to write the controller methods like this:

world_travel_locations

and then use url_title to transform those into SEO friendly URL's?

Kind Regards
#2

[eluser]bretticus[/eluser]
I just tried your example on a project I am working on and it worked just fine:

Code:
$route['world-travel-locations']  = 'videos/index';

I used http://domain.com/world-travel-locations.

What do your routes look like? What do you have configured for $config['uri_protocol']? Are you hiding the index.php with mod_rewrite? If so, what does your .htaccess file (or equivalent) look like?
#3

[eluser]tonanbarbarian[/eluser]
one idea that is a bit more work than using the routes config file, but may make it easier to manage in some ways, is to store the routes in a database.

then you use a pre_system hook to lookup in the database and then modify the $_SERVER vars necessary to have the route convert correctly
#4

[eluser]Saints77[/eluser]
Hi Bretticus

Thanks for your reply and assistance.

I believe I've cracked it now (it's actually working) but it's more a case of getting used to codeIgniter's way of doing things than anything else. I understand the MVC design pattern in theory but translating that into practice can be tricky!

The following sections indicate how my files are coded for the routes to work:


Routes.php
$route['world-travel-gallery'] = "gallery/index";
$route['sculpture-digital-media-creative-work-portfolio'] = "portfolio/load_portfolios/";


config.php (testing on localhost right now so URL is not too pretty!)
$config['base_url'] = "http://localhost/~name/project_sites/site_name/year/";
$config['index_page'] = "";


htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|javascript|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]


I'm not sure where I may have been going wrong or if there is something I am fundamentally missing with any of the above. Guess that's why they call it a learning curve Smile

Appreciate your time and suggestions. It's thanks to people like you that people like me can actually crack niggles like these! Smile
#5

[eluser]Saints77[/eluser]
Hi tonanbarbarian

Thanks for the suggestions.
That's definitely an idea I'll look into for future development.




Theme © iAndrew 2016 - Forum software by © MyBB