Welcome Guest, Not a member yet? Register   Sign In
routes question
#1

[eluser]adt6247[/eluser]
Hi... I just recently re-wrote my personal web site using CodeIgniter -- it's so much cleaner now! Best of all, the URL's are comprehensible by humans!

I'm having a problem setting up routes. I want the links on my old site to redirect to what they will be now. On my old site, the page URL's looked like this:

/page.php?pid=1

on my new site, they look like this:

/page/view/1

I tried setting up the following route:

$route['page.php?pid=:num'] = "page/view/$1";

But no luck. What am I doing wrong? I also tried putting () around the :num, and I tried :any.
#2

[eluser]TheFuzzy0ne[/eluser]
Try this:
Code:
$route[‘page\.php\?pid=(:num)’] = “page/view/$1”; # <-- Note: the . and the ? are escaped, and the :num is captured

The code's not been tested, but should work.
#3

[eluser]pistolPete[/eluser]
If you are using apache I'd recommend using mod_rewrite and a HTTP redirect. As a result, search engines will only index your new sites in future.
#4

[eluser]adt6247[/eluser]
[quote author="TheFuzzy0ne" date="1237185514"]Try this:
Code:
$route['page\.php\?pid=(:num)'] = "page/view/$1"; # <-- Note: the . and the ? are escaped, and the :num is captured

The code's not been tested, but should work.[/quote]

Didn't work... thanks for the attempt.
#5

[eluser]adt6247[/eluser]
[quote author="pistolPete" date="1237217763"]If you are using apache I'd recommend using mod_rewrite and a HTTP redirect. As a result, search engines will only index your new sites in future.[/quote]

I can't figure out how to get that to work... This is the best I could come up with:

RewriteCond ^(.*)$ page.php\?pid=$1
RewriteRule ^(.*)$ /index.php\?/page/view/$1
#6

[eluser]adt6247[/eluser]
I found an adequate solution to this problem. I put the following code in error_404.php:

Code:
$remap_list = array(    'page.php?pid='            => '/page/',
                        'news.php?eid='            => '/blog/entry/',
                        'photo_album.php?aid='    => '/photo/album/'
                        );

$pieces = explode('/', $_SERVER['REQUEST_URI'] );
$piece = array_pop( $pieces );
$path = implode('/', $pieces);

foreach( $remap_list as $old_page => $new_page ) {
    $len = strlen($old_page);
    $request_page = substr($piece, 0, $len);
    if( $request_page == $old_page ) {
        $page_id = substr($piece, $len);
        $new_url = $path . $new_page . $page_id;
        header( "HTTP/1.1 301 Moved Permanently" );
        header( "Location: $new_url" );        
        die();
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB