Suppose, you want to provide legacy URLs when porting the page to a new version. I need to do this, as I am writing the IdeaDay Import Wizard.
An example:
-
The new page will be under /my/new/page
-
You want a legacy alias under /legacy_path/legacy_name
There is a function $page->addCollectionAlias($c); which will alias your Collection UNDER another Collection (essentially adding the page with the same name elsewhere). We could use this, but would need to work around the new page's name and cHandle (which will change: page != legacy_name)
How does C5 handle this internally, when editing page aliases?
/concrete/startup/process.php contains the code (look for else if ($_POST['update_metadata']) and continue to read).
It essentially sets $data['ppURL'] to the aliases (new AND old), and uses $page->update($data);
There is one important thing to consider: to add a new path, the key needs to be a string! This had me baffled for one hour.
So, the entire code to add one new alias, AND keep all the old ones will be:
$this_page_paths = $in_pg->getPagePaths();
$new_paths = array();
foreach($this_page_paths as $path){
if (!$path['ppIsCanonical']) {
$new_paths[$path['ppID']] = $path['cPath'];
}
}
$new_paths['add_path'] = $add_alias;
$data = array();
$data['ppURL'] = $new_paths;
$in_pg->update($data);
$in_pg is the page you want to add the alias to. It is important that you check for the path being canonical, else your main page path will be overwritten (and the page will be redirecting to /). The new path ($add_alias) is added with a string (it does not matter which string you use).
We could use rescanPagePaths to do it directly, but we should not: update fires on_page_update events, for instance.
Now to the second part: modifying .htaccess to provide compatibility.
RewriteRule ^(.*)\.phtml(.*)$ $1$2 [L]
By adding this rule you will be stripping out .phtml from your links -> thus, compatibility with the following path from our example would be preserved:
/legacy_path/legacy_name.phtml
This rewriting is necessary, as Concrete does not allow dots (.) in page paths – it replaces them by an underscore.

Was mache ich?