Not recording visitors who are redirected to mobile version

Hi, I have a redirect set up in htaccess that anyone on a mobile device is redirected to the subdomain m.
Matomo is not recording visits if this mobile redirect happens.
If I go directly to the mobile subdomain my visit is recorded
Please tell me how can I fix this thanks