Welcome Guest, Not a member yet? Register   Sign In
Naming Controllers for Keyword Rich URLs - Good or Bad practice?
#1

[eluser]JamesTaylor[/eluser]
Hi guys i'm just planning out a site that i'm going to build and am considering the best way to name my controllers and methods... i'm thinking in terms of SEO and the resulting URLs which be generated.

The site will is going to be in a directory and contain reviews - for arguments sake lets say a directory / review of coloured pencils available in the uk.

The domain name contains the keywords of the subject but is quite long - www.theukcolouredpencilguide.co.uk

The main sections of the site will be searching the directory of coloured pencils and then reading reviews of the pencils so the main controllers will be for searches and reviews with various methods in each controller... how would people name these controllers / methods? short and sweet to the point or so they are keyword rich?

i'm think they could either be named:

short and sweet
...pencilguide.co.uk/search/location
...pencilguide.co.uk/search/alphabetical

Keyword rich
...pencilguide.co.uk/pencilsearch/pencillocation
...pencilguide.co.uk/pencilsearch/pencilalphabetical

or even a combination
...pencilguide.co.uk/pencilsearch/location
...pencilguide.co.uk/pencilsearch/alphabetical

I guess its a judgement call, but i don't want to penilised by search engines for keyword stuffing but equally i don't want to miss out on an easy SEO opportunity! What have other peoples experiences been of this kind of scenario?

Any advice would be much appreciated.

Thanks

James
#2

[eluser]Michael Wales[/eluser]
The names of your controllers and methods have nothing to do with your URL - that is called routing. Name your controllers and methods based on the objects they interact with and what that method is doing to those objects.
#3

[eluser]JamesTaylor[/eluser]
[quote author="Michael Wales" date="1265232962"]The names of your controllers and methods have nothing to do with your URL - that is called routing. Name your controllers and methods based on the objects they interact with and what that method is doing to those objects.[/quote]

Please bare with me on this i may be about to learn something and deapen my understanding of MVC and CI!

I can appreciate that technically the naming of controllers and methods may not truely be the url but when pages are viewed in a browser and indexed they are so by the name of the domain / controller / method which inturn is creating an address by which users view the pages?

I tend to split my controllers by the specific portion of the site they cover.

i.e on a company website which has 'about us', 'portfolio' and 'clients' sections i would have a controller named after each section:

a controller for 'about us' named 'about_us' which has all the required methods in it

the methods are then named after sub-pages of the section if required. For example a sub page of 'about us' section may be 'company history' or 'key people' so the methods would be named 'company_history' or 'key_people'.

This would then create what i am referring to as its url (what is seen in the address bar) and be indicative to what is being viewed

i.e:
www.companyname.com/controller/method
www.companyname.com/about_us/company_history

Am i going about this in the wrong way? From what i understand the url plays a role in SEO, however large or small it may be. Are you therefore suggesting that to create the desired SEO'd urls routes should be created in the routes config file as opposed to just naming the controllers and methods as desired to create the same effect?

I am not planning to name anything extremely erronous but if the site about pencils having 'search_pencils' in the url rather than just 'search' would be desirable in terms of SEO?

Thanks

James
#4

[eluser]Michael Wales[/eluser]
The URL of domain.com/controller/method is just the default way - a way for you to access your website before you learn about routing.

We'll use your example here, from a developer standpoint it makes much more since to have one controller named pages. Let's assume your content is in a database:

Code:
class Pages extends Controller {

  function Pages() {
    parent::Controller();
  }

  function view($slug) {
    // Code here to go get the data from the database, based on slug, and then push it to a view
  }

}

Alright, so, as we're browsing through our directories we know that class deals with Pages. Just plain old content, pulled out of the database - nothing real special. But - we want SEO friendly URLs right? We want people to be able to go to domain.com/about-us and domain.com/contact-us, right?

This is where routing comes in to play:
Code:
$route['([a-z-]+)'] = 'pages/view/$1';

This says: anything that matches domain.com/??? where ??? is a string containing lowercase letters and dashes, send it to the pages controller, view method, passing the string in ??? to that method.

You're getting the best of both world here - your code makes sense to a developer and your URLs are SEO friendly.

Let's take your search for example: First of all, ditch the underscores. Matt Cutts and virtually every SEO out there agrees, dashes are preferred. Secondly, I would format the URL as such: domain.com/search/pencils/bic - it's pretty easy to tell from that URL that you are search pencils for the word "bic".

So, we have our store and we're selling all kinds of products, well we need a products class right? A Controller to handle these objects.

Code:
class Products extends Controller {

  function Products() {
    parent::Controller();
  }

}

Alright, now we know we need to be able to search these products:
Code:
class Products extends Controller {

  function Products() {
    parent::Controller();
  }

  function search() {
  }

}

For SEO friendliness, we want to include a product type in the URL:
Code:
class Products extends Controller {

  function Products() {
    parent::Controller();
  }

  function search($product_type = NULL) {
  }

}

And lastly, we're going to need a place for our search term:
Code:
class Products extends Controller {

  function Products() {
    parent::Controller();
  }

  function search($product_type = NULL, $query = NULL) {
  }

}

We could now access this page at domain.com/products/search/pencils/bic - which isnt' that bad, but we want to ditch the products controller from this URL. Routing!

Code:
$route['search/([a-z-]+)/(:any)'] = 'products/search/$1/$2';

Hope this helps - you can check out more of the magic of routing in the User Guide.
#5

[eluser]Snaver[/eluser]
Yes you are correct in that the actual url's of pages have a slight influence on the relevance of the page and in doing so the total 'SEO Score'.

As for naming your controllers.. Name them something short and sweet (and relevant) i.e a controller named Search with a function named location(). Then using your routes.php config file inset this entry.

$route['/pencilsearch/location'] = "search/location";

I believe this would work! Please see http://ellislab.com/codeigniter/user-gui...uting.html
#6

[eluser]Michael Wales[/eluser]
Quote:Search with a function named location()

Yucky yucky yucky. Sure, this would work but it's horrible development practices. Controllers should almost always be named objects (cars) and the methods are things you can do to those objects (drive the car).

Seeing a controller named "search" makes me think we are storing, manipulating, users search data - maybe the strings people search for. $Search::location() - maybe a geographic heatmap of where Google searches are coming in from?

When naming classes ask a few questions:
1. What am I trying to do?
2. What am I doing this to?

#1 is the method name, #2 is the class name.

Good examples:
$Article::view()
$Product::create()
$User::delete()

The only time this train of thought should be deviated from is in regards to list() in which case I usually just use index() because that's typically what you would expect. I go to domain.com/pencils I expect a list of pencils you have for sale.
#7

[eluser]derekt[/eluser]
Michael - thank you *very* much for your detailed explanation - everything just clicked after I read your reply.




Theme © iAndrew 2016 - Forum software by © MyBB