Welcome Guest, Not a member yet? Register   Sign In
Force route case
#1

[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.



e.g.

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

any ideas?
#2

[eluser]xwero[/eluser]
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
Code:
$route[’news|NEWS’] = “c_news”;
Your problem is solved.
#3

[eluser]Billy Khan[/eluser]
Thanks.

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

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

[eluser]xwero[/eluser]
you can do
Code:
$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.
#5

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

[eluser]wiredesignz[/eluser]
Very clever Xwero Wink
#7

[eluser]xwero[/eluser]
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
#8

[eluser]Unknown[/eluser]
That saved a few hours of work. Thanks for posting.
#9

[eluser]toltmanns[/eluser]
Seems like the solution to use sql_regcase() is no longer viable, as the function is now deprecated.




Theme © iAndrew 2016 - Forum software by © MyBB