• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Force route case

[eluser]Billy Khan[/eluser]
I have a site that some users are starting to link to, they have changed the case of some links which is ending up with page not found errors.

I have trawled this forum and cant seem to find a solution. Ideally, i would like to get CI to ignore uri case. I can see that routes.php can handle regular expressions. But i am unsure as to how to make use of it.


$route['news'] = "c_news";
Yet www.mysite.com/NEWS is breaking and is calling my default controller.

any ideas?

from a SEO point of view this is a good thing because it prevents plummeting your pagerank because of double content. So i think the request for case insensitive uri routing is not a going to stick.

The routing is nothing more than a hidden preg_replace so if you do
$route[’news|NEWS’] = “c_news”;
Your problem is solved.

[eluser]Billy Khan[/eluser]

What about mix case? , e.g.
Would i need to put one in for all?
$route[’news|NEWS|News|NEWs’] = “c_news”;

I know some mix case examples are highly unlikely but i want to cover all bases.

you can do
$route[sql_regcase('news')] = 'c_news';
this function creates following expression for you : [nN][eE][wW][sS]
So you could either use the function or just add the expression as your route key.

[eluser]Billy Khan[/eluser]
Worked a treat, many thanks!

Very clever Xwero Wink

the function is handy in this situation because you can't do /news/i. I stumbled on it looking for a solution for other regex problems Smile

That saved a few hours of work. Thanks for posting.

Seems like the solution to use sql_regcase() is no longer viable, as the function is now deprecated.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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