How do you create a HTTP 302 in order to redirect mobile users to a different URL: example.com to m.example.com ?
Google recommends HTTP 302 for redirecting mobile users:
"HTTP redirection is commonly used to redirect clients to device-specific URLs. (...) It does not matter if the server redirects with an HTTP 301 or a 302 status code, but use of 302 is recommended whenever possible."
As a better technique than JavaScript redirect:
"Be aware of the latency caused by the client side of redirection due to the need to first download the page, then parse and execute the JavaScript before triggering the redirect."
https://developers.google.com/search/mobile-sites/mobile-seo/separate-urls