Remove part from dynamic url and redirect

I’ve fixed it with the following code:

/**
 * Redirect '/tag/[0-9]/{tag_name}/' to the correct tag.
 */
add_filter('request', function($qv) {
    if (array_key_exists('category_name', $qv) && preg_match('/(tag\/)([0-9]*)/', $qv['category_name'])) {
        $qv = [
            'tag' => $qv['name']
        ];
    }

    return $qv;
});

I’m not sure if this is the right way, but it works!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)