Redirect within

I have a page that represents a city. In a hook, I am doing a geocoding lookup in Google Maps and then renaming the page according to what Google tells me it should be, in order to avoid duplicate city pages with different pronunciations.

Sometimes the page I am ‘moving’ to already exists. Then I want to delete the current page and redirect the user to the user that was already there.

I have gotten as far as being able to delete the current page if there is one with the same slug already there. But I can’t find a way to redirect the panel to it…

This should work:

$uri = $page->uri(); // whatever page uri you need here
$this->panel()->redirect('pages' . DS . $uri . DS . 'edit');

wow - I wasn’t expecting it to be possible - thanks!

Another option is:

$blog = panel()->page('blog'); // must be an instance of Kirby\Panel\Models\Page
$this->panel()->redirect($blog, 'edit');