You can try to do this with cloudflare. It has this option.
Mobile Redirect
Redirect visitors that are using mobile devices to a mobile-optimized website.
Code:
What does Mobile Redirect do?
Mobile Redirect automatically redirects visitors using mobile devices to a website specifically for those devices.
Cloudflare redirects visitors at the edge. This avoids a request to your origin server, directing visitors to your mobile-optimized website even faster.
Cloudflare must be enabled on %{name} or www.%{name} to use Mobile redirect.
What Mobile Redirect setting should I use?
Drop path: Redirect all mobile requests to your mobile-optimized website homepage.
Example: http://%{name}/page.html → http://mobile.%{name}
Keep path: Redirect all mobile requests to the same resource hosted on your mobile-optimized website.
Example: http://%{name}/page.html → http://mobile.%{name}/page.html