Part of the EllisLab Network
   
2 of 2
2
So close with a mod_rewrite that changes underscores to hyphens for SEO. Can anyone close it out?
Posted: 11 May 2011 09:52 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  7
Joined  04-27-2011

I tried this as well and it didn’t work.  The router code is different in the later version of CI I think.

Profile
 
 
Posted: 12 May 2011 04:05 AM   [ Ignore ]   [ # 17 ]  
Summer Student
Total Posts:  2
Joined  05-08-2011

Which method have you used mteejay? I’m using the latest CI and it’s working for me.

Profile
 
 
Posted: 26 October 2011 11:10 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Rank
Total Posts:  54
Joined  11-06-2009
jaysonic - 08 May 2011 06:31 AM

Another solution, which has been posted although it modifies all the segments, is as follows.

Create the MY_Router.php file in /application/core and in it place the following code:

<?php
public function _set_request($segments){
    
// Fix only the first 2 segments
    
for($i 0$i 2; ++$i){
        
if(isset($segments[$i])){
            $segments[$i] 
str_replace('-''_'$segments[$i]);
        
}
    }
    
    
// Run the original _set_request method, passing it our updated segments.
    
parent::_set_request($segments);
}
?> 

This just modifies the first 2 segments in your URL, but only if they are set. Hopefully that helps someone.

why don’t you just do

parent::_set_requeststr_replace'-''_'$segments ) ); 

?

Anyway, this solution works only because CI is not written in true OOP manner. The code hasn’t completely been upgraded from the PHP 4 days. If you look at the source code of the CI_Router class, the _set_request function is supposed to have private access; that is, no other class—not even the classes that inherit from it—is supposed to access it or override it. If in the next release they decide to put “private” in front of it, then your upgrade will not be easy, especially if this is not the only modification of this kind.

I know, a little late, but I suggest the hooks method.

Profile
 
 
   
2 of 2
2