Have a site and within that site I have numerous pages within Geographic folders (North, South, East, West etc) featuring destinations.
These pages are now deleted as they have now been moved to a new site/domain.
So essentially I do have
And it’s now replicated at
So I would like to set up a redirect to all the pages from one site to another.
I have installed Redirector and I also have csv of all the URLs but I don’t think it will allow me to redirect to another domain.
Is the only way to do this via .htaccess ??
Thanks
This should be possible. Just use the complete url https://domain.com/...
in the target field.
Ive tried that and no luck
I’ve also tried raw csv but that fails I’ve tried various input styles with/ without semi-colon and commas
" etc
“madagascar-guide-the-western-region-of-madagascar.html,;https://www.primemadaguide.com/madagascar-guide-the-western-region-of-madagascar.html; ”
dejaya
September 20, 2022, 1:57pm
4
That’s odd, the UI accepts a full URL for me fine.
MODX 3.0.1-pl
Redirector 2.0.10-pl
I agree about the CSV import though - it fails on any combination I try - even for just a single line.
When a redirect is created manually and the target contains '://'
, there is a check with the PHP function get_headers to see if the target-URL exists.
During an CSV import, the target field is also validated, but only local URLs are allowed.
case 'target':
$target = $this->getProperty('target');
$this->modx->getParser();
$this->modx->parser->processElementTags('', $target, true, true);
$criteria = array('uri' => $uri);
if(!empty($context)) { $criteria['context_key'] = $context; }
$resource = $this->modx->getObject('modResource', $criteria);
if(empty($resource) || !is_object($resource)) {
return false;
}
break;
This validation has to be extended to allow for full links to other domains.
dejaya
September 20, 2022, 3:58pm
6
That makes sense - but the import CSV seems to fail even if a local target is chosen:
Maybe I’m misinterpreting the advice:
Notice: format of the CSV must be “pattern;target;context”, where “context” may be skipped or empty.
Also tried:
You can’t use [[~1]]
. You have to use the actual alias:
some-page.html;some-parent/some-other-page.html;
Also, here is the replacement code to allow external redirects in the import:
case 'target':
if(strpos($uri, '://') !== false) {
$headers = @get_headers($uri);
if(empty($headers)) {
return false;
}
} else {
$criteria = array('uri' => $uri);
if(!empty($context)) { $criteria['context_key'] = $context; }
$resource = $this->modx->getObject('modResource', $criteria);
if(empty($resource) || !is_object($resource)) {
return false;
}
}
break;
1 Like
dejaya
September 20, 2022, 4:25pm
8
Does that actually work for you @halftrainedharry ?
Yes, it does.
If there is an error, it should log an error message to the MODX error log.
Alternatively the extra SEO Suite also allows redirects. But there is no possibility to import from a file.
If nothing else works, there is always the possibility to add the data directly to the database table: modx_seosuite_redirect
for SEO Suite or modx_redirects
for Redirector .
dejaya
September 20, 2022, 7:16pm
10
halftrainedharry:
Yes, it does.
This was really baffling me - turns out I didn’t have FURLs enable on my test site so all targets were getting rejected using the CSV import.
I can see it works now and also that your fix above allows the addition of full external links
Hopefully that will work for @gavinbaylis too
bobray
September 20, 2022, 9:35pm
11
WebLinks should also forward to external pages as long as the content field holds a full URL. That might be easier to implement. You should be able to just convert the old pages to WebLinks and put the new URL in their content field.
Where do I place that specific code please?
Currently, I’m changing each page individually and it’s getting rather tedious
Ignore that above, I’ve worked it out, now to see if it works!
In the file core/components/redirector/processors/mgr/import/import.class.php
in the function “validate” (lines 114 to 125).
Still had four failed with this quick import
madagascar-destinations-guide-ambodinonoka.html;https://primemadaguide.com/madagascar-destinations-guide-ambodinonoka.html;
guide-des-destinations-de-madagascar-kimony.html;https://primemadaguide.com/guide-des-destinations-de-madagascar-kimony.html;
madagascar-destinations-guide-bedo-lake.html;https://primemadaguide.com/madagascar-destinations-guide-bedo-lake.html;
guide-des-destinations-de-madagascar-lac-bedo.html;https://primemadaguide.com/guide-des-destinations-de-madagascar-lac-bedo.html;
I’m not sure why it fails (The targets seem to exist. Maybe check the MODX error log).
If you are really sure that the data is correct, then just change the code in the validate function to always return true;