I want to redirect a deep link like this: https://www.mywixsite.com/lessons/{id} to my wix site homepage (not in the error page where it redirects now).
The id value in the url is different every time, as the deep link changes. How can I achieve redirection to the homepage from the above url for every different id?
Wix gives you the option through the dashboard to redirect specific urls like https://www.mywixsite.com/lessons to another page, but what happens when the url includes a value that is changing every time?
CodePudding user response:
You can use wix-router to catch lessons/{id}
requests and redirect to the home page.
- Create the lessons router (here is how)
- Add the following code to the routers.js file (which created for you in the last step)
export function lessons_Router(request) {
const id = request.path[0];
return redirect(`https://www.mywixsite.com?id=${id}`);
}
It will redirect the user from https://www.mywixsite.com/lessons/1 to https://www.mywixsite.com/?id=1 so you can identify from what lesson id the user came from.
If you don't need the id, you can remove it of course.