How to Redirect Osclass Urls to Subfolder ( Seach results SEO )

How to Redirect Osclass Urls to Subfolder? ( Seach results redirecting in GOOGLE etc )
I decided to migrate 20 categories and their items from home page to a subfolder. After migrate completing, I have removed categories from homepage and it is now viewable on subfolder installation.

But those urls are already crawled under homepage, how can I SEO redirect those urls to subfolder?

Example:
www.mysite.com/categories/ >>>> www.mysite.com/subfolder/categories

Which code I need to use?

It’s better to do this through your server.
A simple tutorial to that with apache.

Paste below code to your theme functions.php

<?php function cust_redirect_on_item_not_exists($item) { if( count($item) == 0 ) { $category = Category::newInstance()->findBySlug(preg_replace('~^.*/(.*)/.*$~', '$1', $_SERVER['REQUEST_URI'])); osc_redirect_to(osc_search_url(array('sCategory' => $category['pk_i_id'])), 301); exit; } return $item; } osc_add_filter('pre_show_item', 'cust_redirect_on_item_not_exists'); ?>

I am used on my website - https://in.nearmeads.com