tags:

views:

518

answers:

1

I want my website to redirect mobile users from mydomain.com to m.mydomain.com (unless they have specifically asked to see the non-mobile site).

I was doing this in my application using WURFL, but I want to enable page caching. If page caching is on, the application will never be reached to know to redirect the mobile user, and so I need nginx to do this.

Apache has modules such as Apache Mobile Filter that make use of WURFL.

Is there any good way to detect a mobile browser in nginx? I'd rather not just come up with a user-agent regex since there are so many different mobile user agents that are always changing.

+1  A: 

I don't believe there is a dedicated nginx core or third-party module for this. Since any module would simply test the user-agent anyway, I can't imagine anyone creating a module for this specific purpose.

However, it should be relatively simple to set-up a check on the user-agent and redirect. You may find it preferable to check for Gecko/IE/webkit/opera explicitly and redirect everything else to your mobile site - that way you're maintaining a smaller ua regex, plus you'd be catering for the mobile safari (iPhone/iPod Touch) by keeping them on your main website. Its then a simple step to special-case for that browser should you wish to.

Furthermore, you should be able to check cookie contents in your nginx config to decide whether to redirect based on the user-agent's preferences.

digitala