CodeIgniter Forums
Fully qualified SEO URLs, how to be allowed to use them? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Fully qualified SEO URLs, how to be allowed to use them? (/showthread.php?tid=10192)

Pages: 1 2 3


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 11-21-2008

[eluser]saijin[/eluser]
[quote author="ray73864" date="1227275388"]negatory, you can't have a dash in the controller name, i can't really see why you would need to have it either.[/quote]

for SEO Friendly URL..


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 11-21-2008

[eluser]johnwbaxter[/eluser]
Google have said that they treat underscores in urls exactly the same as a dash in a url. They said this some time ago (i think it's on Matt Cutts blog).

So there you go, problem solved.


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 11-21-2008

[eluser]Colin Williams[/eluser]
Meh.. Unfortunate you make that point, audiopleb. I don't know why CI doesn't just attempt to map dashed controller/function URI parameters to underscored class and class member function names. Well, actually, I do have a hunch why this isn't done, but it still seems slightly ridiculous.

Three simple solutions remain. 1.) Abandon the dashes and adopt underscores, like audiopleb suggests. 2.) Override the necessary Router class member function(s) to make CI think of dashes as underscores. 3.) Lose the two-word URI param altogether. Just name the class "Outsourcing." This last option is my favorite Smile


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 08-13-2009

[eluser]Joshua Logsdon[/eluser]
So far, so good with overriding the Router library's _set_request() method to change dashes found in the first two segments to underscores.

Attached is the MY_Router.php file (inside the .zip) that I'm using in my application/libraries/ directory and here is the addition to the method mentioned above:

Code:
for ( $i = 0; $i < 2; $i++ )
{
    if ( isset($segments[ $i ]) && strpos($segments[ $i ], '-') !== FALSE )
    {
        $segments[ $i ] = str_replace('-', '_', $segments[ $i ]);
    }
}



Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 09-28-2009

[eluser]b3nst3wart[/eluser]
Try my solution posted in a similar thread here:

http://ellislab.com/forums/viewreply/644012/


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 09-29-2009

[eluser]Eric Cope[/eluser]
switch to underscores.


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 12-17-2009

[eluser]jv2222[/eluser]
[quote author="Joshua Logsdon" date="1250163628"]So far, so good with overriding the Router library's _set_request() method to change dashes found in the first two segments to underscores.

Attached is the MY_Router.php file (inside the .zip) that I'm using in my application/libraries/ directory and here is the addition to the method mentioned above:

Code:
for ( $i = 0; $i < 2; $i++ )
{
    if ( isset($segments[ $i ]) && strpos($segments[ $i ], '-') !== FALSE )
    {
        $segments[ $i ] = str_replace('-', '_', $segments[ $i ]);
    }
}
[/quote]

Kudos and thanks for the MY_Router.php works perfectly! Smile


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 12-17-2010

[eluser]dynZack[/eluser]
Extend the Router class with the following MY_Router :

Code:
&lt;?php
class MY_Router extends CI_Router
{
function _set_request($segments = array()) {
  parent::_set_request(str_replace('-', '_', $segments));
}
}



Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 04-27-2011

[eluser]mteejay[/eluser]
[quote author="Joshua Logsdon" date="1250163628"]So far, so good with overriding the Router library's _set_request() method to change dashes found in the first two segments to underscores.

Attached is the MY_Router.php file (inside the .zip) that I'm using in my application/libraries/ directory and here is the addition to the method mentioned above:

Code:
for ( $i = 0; $i < 2; $i++ )
{
    if ( isset($segments[ $i ]) && strpos($segments[ $i ], '-') !== FALSE )
    {
        $segments[ $i ] = str_replace('-', '_', $segments[ $i ]);
    }
}
[/quote]

Is this solution still working with the latest release of CI (2.0.2)?


Fully qualified SEO URLs, how to be allowed to use them? - El Forum - 05-30-2011

[eluser]Joshua Logsdon[/eluser]
Got questions from a couple people recently. Keep in mind that solution is almost 2 years old now!

The idea was how can I get around managing routes.php config when I'm switching around lots of controllers, etc. So overriding the router may be overkill for most situations and stick to just managing routes.php like mentioned here:
http://ellislab.com/forums/viewthread/187580/#889493

In Router.php's _validate_request method, I change '-' to '_' when $segments[0] is checked. In another thread there is a good tip to do this for the set_class and set_method methods and so I got rid of changing the _set_request method with that tip.

Attached is the MY_Router I'm using in CI 2.0.2, now in \application\core\