Re-direct to a URL from the backend

Hi there,

You can redirect requests to access router pages on the backend when a router URL is requested.

On the backend, inside your routers.js file, and assuming that you’ve created a router with a prefix of " redirect ".

import { redirect, notFound } from 'wix-router';

export function redirect_Router(request) {
    const { path } = request;
    if (path[0] === 'nasriya') {
        return redirect('https://nasriya.net', 307);
    }
    
    return notFound();
}

export function redirect_SiteMap(request) {
    return [];
}

In the code above, any requests coming to “/redirect/nasriya” will redirect the visitor to “https://nasriya.net”.

Please note that this only works on the URL when it’s visited, it can’t be ran if otherwise.

Hope this helps~!
Ahmad