Routing index.php parameters

Hi!

I am making redesign of website that already has content.

The old site uses old urls with parameters like this

/index.php?option=com_content&task=view&id=711&Itemid=28

The only imporant thing actualy is id which is id of the article. Articles were parsed so they have the oldarticleID so i can get them by id. I need to retain old urls along the old ones.

So i was thinking i will do something like this:

c::set('routes', array(
  array(
    'pattern' => 'index.php(:all)',
    'action' => function ($all) {
    	//parse query
    	parse_str($all, $output);
    	//find page with same id
    	$page = $site->search($output['id'], 'originalid');
    	//redirect 
    	return site()->visit($page);
    }
  )
));

But of course when you do index.php? and start parameters it goes imidiately to index.php so it doesnt work. If there is no ? then it works.

So is there a any way to do it in php or i need to touch webserver settings?

Thank you!

Using index.php as route pattern does not work unfortunately as it’s removed from the search string by Kirby, but you can use the following in your config:

if(str::startsWith(server::get('request_uri'), '/index.php?')) {
  if($page = site()->index()->findBy('originalid', get('id'))) {
    go($page);
  } else {
    go('error');
  }
}

Wow

You just made it for me. Thank you Lukas. Works awesome.