• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to get around using hyphens in controller class names for SEO

#1
Hi,

Am a bit stuck about how to best go about this and was hoping for a suggestion or two.

I have a site with urls like http://www.mydomain.co.uk/wooden_tables/family_tables

An SEO company I am working with told me that it would be best to replace the underscores with hyphens which I did not believe, until I googled it, and was suprised to find google themselves say that they use underscores to join words,  and hyphens to seperate them. So they see the example url above as being "woodentables/familytables", not "wooden tables/family tables".

So, stupidly I proceeded to change all my controller classes names and site urls to dashes, without testing one example first, just thinking 'ah, that is news to me but the change will be quite simple to do'. Only to then discover that PHP does not allow hyphens in class names. :-(

So then I thought, I know, I will just use .htaccess to redirect all the underscores, but redirection does not really solve the problem. Then I thought, perhaps I can write a router to reroute the requests, but since this affects the entire site, that would mean writing routes for all the dynamically generated urls.

So I need to be able to use the url http://www.mydomain.co.uk/wooden-tables/family-tables, be able to list that url as the canonical link and in the sitemaps, use that url in links from other pages, but use a class that has the name wooden_tables and method family_tables.

Does anyone have a suggestion how I should best approach this?

Thanks in advance,

Best wishes,

Paul.
Reply

#2
In application/config/routes.php you have: $route['translate_uri_dashes'] = FALSE;
Set it to TRUE, change the controller and file names back to underscores, and that's it...
Reply

#3
Wow. I did not know that. Once again CI amazes me :-)

Every time I think I have run into an insoluble problem CI has got there first, ages ago, and already solved it :-)

I had already changed all the controller names back to underscores anyway just to make the site work again, but, I will have to upgrade the site to the latest version now (it is an old site), which I had been meaning to do for a while but just had not got around to it and that option is not in the version this site is running. :-(

Thank you Avenirer, will try that out as soon as I have done the upgrade (which I will probably do tomorrow).

Am really delighted this will be an easy fix, and now I can do it on lots of sites where I made the same underscore/hyphen SEO error.

Thank you again,

Paul
Reply

#4
I've not used this feature, but you may want to check if the routes are accessible with underscores, because you would not want to be penalized for duplicate content.
Reply

#5
Hi,

The upgrade went very smoothly indeed! Took about an hour all in. (The only head scratcher was when one of the models stopped working but that was simply due to the fact I had forgotten to upgrade the session table. The old format had a different structure).

Once it was all working I changed the setting to 'TRUE' and Ta-Da, as if by magic I can now put hyphens in my urls :-)

@skunkbad
Yes, duplicate content would be a problem, as both forms of url work. However, I have a canonical link set for every page so that is not an issue in this case, although worth pointing out. Personally I am gald both work as I now have to work through all the links and database info converting it to use the hyphens where I can. During this process though, and even if I miss a few, the site will still function perfectly.

I am just checking that I have not used hyphens anywhere that should not be replaced, but the setting only changes the methods and function parts of the segments, which is perfect.

As I said previously, CI continues to impress me. I love CI so much :-)

Thanks again for the help on this,

Best wishes,

Paul.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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