HI
I would like to activate “use_alias_path” after running the website for a while (don’t ask for the reasons ). Is it possible to keep the old urls of the existing resources?
There are a LOT of pages. So i don’t want to open all and activate “fix URL” or add the 301 redirect manually to “SEO Tab”.
Is there any solution for my Problem?
To add a new redirect to “SEO Tab” programmatically you can probably do something like that:
<?php
$modelPath = $modx->getOption('stercseo.core_path', null, $modx->getOption('core_path') . 'components/stercseo/') . 'model/';
$modx->addPackage('stercseo', $modelPath, null);
$new_redirect = $modx->newObject('seoUrl');
$new_redirect->set('url', urlencode('https://www.example.com/old_path'));
$new_redirect->set('resource', $resource_id);
$new_redirect->set('context_key', $context_key); //e.g. 'web'
$new_redirect->save();
Thanks for the mega fast reply!
I am just a designer with technical understanding, but without any programming skills
What I do not understand:
- Where do I use your code? I would have to automatically run through all resources, right?
- Where do I get the current URL of the resource that I have to enter as new redirect url?
- In your example the url is fixed in the code, isn’t it?
Thanks
I will try it next week!