lucy24 - 8:42 pm on May 30, 2013 (gmt 0)
Overlapping a few earlier posts, so there may be redundancies
Ouch. Is this happening in htaccess or config? Most of the time it doesn't make a huge difference. But you're got a horrendously complicated group of Regular Expressions there. If they're in the config file they will be compiled just once, at server startup. In htaccess they have to be recompiled every single time the rule executes, which could bring the server to a crawl.
Constraining the rule to page requests is a definite step in the right direction. But with
you've constrained it to the front page only, which creates a different problem. What if someone has a different page bookmarked or linked? The landing page may not be the front page-- and, conversely, the front page may not be the landing page.
There are further issues. Picking a segment at random:
If the " OS" element is optional-- and there's no closing anchor-- why does it need to be there at all?
Slashes do not need to be escaped in mod_rewrite. (There are a couple of mods where you do need to-- same principle as in programming languages where regular expressions are delimited with /slashes/ --but these are exceptions.)
If you have a pipe-delimited group, enclose the whole thing in parentheses-- in this case, non-capturing ones. This is for your own safety and sanity; throw an anchor into the mix, and suddenly the rule does something completely different from what you intended.
It is probably easier to detect mobile devices negatively: If the UA isn't one of a handful of standard browsers, it's a cell phone. But you also need to consider tablets. These can go either way depending on the site: for display purposes they generally behave like browsers; for user-interface purposes they're more like cell phones.
For insurance, give the user a way to override your redirect. A simple cookie will do. mod_rewrite can read and set cookies; you don't have to go off and learn a separate "cookie language" ;)