Creating a copy of a website in a subdirectory, wp-admin redirect problem

If it’s a standard WordPress .htaccess file that won’t be your problem. I’m willing to bet you forgot to change the Site URL values when you imported the database.

You can either edit it in the options table in your database or even in your wp-config file by adding

define('WP_HOME', 'http://mainwebsite.com/test');
define('WP_SITEURL', 'http://mainwebsite.com/test');

to it. You can read more (or other ways to do it) here: https://codex.wordpress.org/Changing_The_Site_URL