Yes, you can do that, on the 404 page, write down this code:
import wixLocation from 'wix-location';
$w.onReady(() => {
const my_domain = 'https://nasriya.net/'; // The other domain
const path = wixLocation.path || []; // The current location data
if (path.length > 0) {
let path = ''; // The current stringified path
path.forEach(directory => {
path = `${path}/${directory}`;
});
// Redirect the visitor to the second domain
wixLocation.to(`${my_domain}${path}`)
}
})
When you land on the 404 page, the code will take the path from the curent location, build the path from the array and redirect you to the the second domain with the same path.
Note: There might be a processing delay, so you’re advised to use a preloader on the page untill the procesing is done.
if (path.length > 0) {
let path = ''; // The current stringified path
path.forEach(directory => {
path = `${path}/${directory}`;
});
// Redirect the visitor to the second domain
wixLocation.to(`${my_domain}${path}`)
}
Write:
if (path.length > 0) {
let pathString = path.join("/");
wixLocation.to(`${my_domain}/${pathString }`)
}
@J.D yes but in my case pathString is “error404” and i want to go to the previuos url.
E.g, the user goes to mywixsite.com/{dynamic_path} and this url dosn’t exist so i want to redirect the user to mycustomdomain.com/{dynamic_path}. The problem is that wix return the user first to error404 page and when i try to get the path { dynamic_path} to do the redirect, the response for wixLocation.path is [“error404”]
Thanks! As J. D. said, your site is using our old rendering engine, which is likely why these issues are happening. I’ve sent the info to our QA team to investigate, and hopefully we can move you over to our new rendering engine. I’ll have more info for you tomorrow.
Strange, the path of the page, for example, https://nasriya.net/some-page doesn’t exist, you visit this page, you’ll get a 404 error as expected, but when reading the path by code, the path is /error404 , which is not what looks on the actual path, this has always been the case.