Welcome Guest, Not a member yet? Register   Sign In
So close with a mod_rewrite that changes underscores to hyphens for SEO. Can anyone close it out?
#19

[eluser]Unknown[/eluser]
[quote author="b3nst3wart" date="1254196458"]Finally solved...

First create a "pre-system" hook by adding these lines to your 'config/hooks.php' file:
Code:
$hook['pre_system'] = array(
    'class'    => '',
    'function' => 'prettyurls',
    'filename' => 'myhooks.php',
    'filepath' => 'hooks',
    'params'   => array()
);

Now create a 'myhooks.php' file within the 'application/hooks' folder and add this function (don't forget to open a PHP tag if this is the first hook):
Code:
<?php
function prettyurls() {
    if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') {
        $newkey = str_replace('-','_',key($_GET));
        $_GET[$newkey] = $_GET[key($_GET)];
        unset($_GET[key($_GET)]);
    }
    if (isset($_SERVER['PATH_INFO'])) $_SERVER['PATH_INFO'] = str_replace('-','_',$_SERVER['PATH_INFO']);
    if (isset($_SERVER['QUERY_STRING'])) $_SERVER['QUERY_STRING'] = str_replace('-','_',$_SERVER['QUERY_STRING']);
    if (isset($_SERVER['ORIG_PATH_INFO'])) $_SERVER['ORIG_PATH_INFO'] = str_replace('-','_',$_SERVER['ORIG_PATH_INFO']);
    if (isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = str_replace('-','_',$_SERVER['REQUEST_URI']);
}

You will probably need to edit your 'config/config.php' file to enable hooks (around line 91 for me):
Code:
$config['enable_hooks'] = TRUE;

Good luck.[/quote]


Actually , this is the best solution. Recommend 100%.


Messages In This Thread
So close with a mod_rewrite that changes underscores to hyphens for SEO. Can anyone close it out? - by El Forum - 08-22-2012, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB