Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to a mobile sub-domain using 51degrees

I'm using the 51degrees API for mobile redirection: http://51degrees.codeplex.com/

  • The desktop site is located at http://www.mydomain.com.
  • The mobile site is located at http://m.mydomain.com.

When a mobile device is detected, using 51degrees, I am able to redirect from from any desktop page to the mobile homepage using the 51degrees configuration only. I.e. http://www.mydomain.com/somepage to http://m.somepage.com/default.

What I am unable to do is redirect to the same page, i.e. from http://www.mydomain.com/somepage to http://m.somepage.com/somepaage.

Is it possible to redirect to the same page?

like image 506
Jaimal Chohan Avatar asked Sep 14 '11 15:09

Jaimal Chohan


1 Answers

Option 1: Use 51degrees for the mobile detection part only and wire up the redirect yourself. Remove the <redirect> element from your web.config and try something like this in your Global.asax file:

void Application_BeginRequest(object sender, EventArgs e)
{
    if (HttpContext.Current.Request.Browser.IsMobileDevice)
    {
        Response.Redirect("http://m.mydomain.com" + Request.RawUrl);
    }
}

Option 2: In the <redirect> element in the web.config file, add the property originalUrlAsQueryString=true. This will send a query string called origUrl to the mobile homepage giving you the option to redirect to the mobile version of the requested page.

like image 184
James Lawruk Avatar answered Sep 23 '22 04:09

James Lawruk