I haven't setup a test, so I'm trying to understand, but with the querystring solution wouldn't that fail on any server side redirects within code? For example a login page. The server wouldn't be aware of the fullsite=1 so the URL would drop the fullsite=1.
Is that correct?
The other option that could work is to have the "View Full Site" link point to a page that writes a cookie and then redirects to the equivalent www page. The redirect-to-mobile rule can have a condition where the cookie doesn't exist.
I haven't setup an end to end example, but it seems to me like it would also work and would be trustworthy throughout the site.
Yes, I believe you're correct in saying that any server-side redirects would invalidate the query string solution (unless the redirects read the query string and persist it on). Thankfully that's not the case with the site that I'm working with.
The only question I have about the cookie solution is if cookies are generally enabled by default, or even supported, on mobile devices. I thought about setting a cookie before going down the route before I learned about the URL rewrite plugin.
My thought was if we take the uncertainty of knowing if the mobile device supports (or has enabled) cookies then it would be a solid solution. Thus the query string solution.
You raise a good point Mike. It looks like it's not accepted as a safe assumption to use cookies on mobile phones:
http://www.w3.org/TR/mobile-bp/#d0e1925. If your site doesn't have any server-side redirects then your solution works great.
And I've just thought of another method that should be very safe and easy to do. Use a 3rd domain name.
For example, www.domain.com should redirect all mobile phones to m.domain.com. Then if someone clicks on "View Full Site" send them to mweb.domain.com. The mweb.domain.com can point to the same site as www.domain.com but you now have a new condition to check
against. Unless something in the site is hard coded to use the full domain name, client-side and server-side redirects should maintain the URL.
Also, add a robots.txt files to ask the search engines to not index m.domain.com and mweb.domain.com.
We are using IIS URL Rewrite module to redirect all request from a mobile browser to m.mymobilesite.com by checking HTTP_USER_AGENT. This works fine and now we need to implement a "View Full Site" link which will allow the user to see the main site. Trying
to achieve this by adding a "nomobile" cookie when user clicks on "View Full Site" link which will be validated and negated by the rule. For some reason my rule doesn't seems to work. Please help.
Rovastar
3324 Posts
MVP
Moderator
Re: URL rewrite for Mobile/Cell phone devices
Nov 18, 2011 11:30 PM|LINK
This regex works ([^.]*)&$
<rule name="remove last ampersand" stopProcessing="true">
<match url="([^.]*)&$" />
<action type="Redirect" url="{R:1}" />
</rule>
Removes ([^.]*) is everything before and
&$ (converts to &$ in the web.config displays correctly in the GUI) matches the & to the last character
The $ operator matches the very last character. Here is a good regex site about the $ operator:
http://www.regular-expressions.info/anchors.html
OWScott
286 Posts
Re: URL rewrite for Mobile/Cell phone devices
Jan 11, 2012 09:04 PM|LINK
Great thread and discussion.
I haven't setup a test, so I'm trying to understand, but with the querystring solution wouldn't that fail on any server side redirects within code? For example a login page. The server wouldn't be aware of the fullsite=1 so the URL would drop the fullsite=1. Is that correct?
The other option that could work is to have the "View Full Site" link point to a page that writes a cookie and then redirects to the equivalent www page. The redirect-to-mobile rule can have a condition where the cookie doesn't exist.
I haven't setup an end to end example, but it seems to me like it would also work and would be trustworthy throughout the site.
Microsoft MVP - IIS
Vaasnet
www.vaasnet.com
mikeberlin
7 Posts
Re: URL rewrite for Mobile/Cell phone devices
Jan 13, 2012 12:06 AM|LINK
Yes, I believe you're correct in saying that any server-side redirects would invalidate the query string solution (unless the redirects read the query string and persist it on). Thankfully that's not the case with the site that I'm working with.
The only question I have about the cookie solution is if cookies are generally enabled by default, or even supported, on mobile devices. I thought about setting a cookie before going down the route before I learned about the URL rewrite plugin.
My thought was if we take the uncertainty of knowing if the mobile device supports (or has enabled) cookies then it would be a solid solution. Thus the query string solution.
OWScott
286 Posts
Re: URL rewrite for Mobile/Cell phone devices
Jan 13, 2012 01:54 PM|LINK
You raise a good point Mike. It looks like it's not accepted as a safe assumption to use cookies on mobile phones: http://www.w3.org/TR/mobile-bp/#d0e1925. If your site doesn't have any server-side redirects then your solution works great.
And I've just thought of another method that should be very safe and easy to do. Use a 3rd domain name.
For example, www.domain.com should redirect all mobile phones to m.domain.com. Then if someone clicks on "View Full Site" send them to mweb.domain.com. The mweb.domain.com can point to the same site as www.domain.com but you now have a new condition to check against. Unless something in the site is hard coded to use the full domain name, client-side and server-side redirects should maintain the URL.
Also, add a robots.txt files to ask the search engines to not index m.domain.com and mweb.domain.com.
Microsoft MVP - IIS
Vaasnet
www.vaasnet.com
anh1e
1 Post
Re: URL rewrite for Mobile/Cell phone devices
Apr 30, 2012 01:45 PM|LINK
Great article.
Found the list of user agent string for mobile browsers http://www.useragentstring.com/pages/Mobile%20Browserlist/
Based on that list, if we search with pattern="midp|mobile|phone", are we going to miss a lot of mobile browsers ?
Rovastar
3324 Posts
MVP
Moderator
Re: URL rewrite for Mobile/Cell phone devices
Apr 30, 2012 02:04 PM|LINK
Although this was initially written nearly 2 years ago I still think that it catches most mobile browsers.
Which ones did you think it would not catch? There may be a few in the change mobile market but most are there that have any significant traffic
halcoberry
2 Posts
Re: URL rewrite for Mobile/Cell phone devices
May 08, 2012 01:51 AM|LINK
I recently wrote a post up with screenshots on using the URL Rewriter to redirect specific browsers.
here it is if you are interested
http://halcoberry.blogspot.com.au/
*edit cause i cant spell :p
browser redirect specific
Dil
2 Posts
Re: URL rewrite for Mobile/Cell phone devices
Nov 01, 2012 08:51 PM|LINK
We are using IIS URL Rewrite module to redirect all request from a mobile browser to m.mymobilesite.com by checking HTTP_USER_AGENT. This works fine and now we need to implement a "View Full Site" link which will allow the user to see the main site. Trying to achieve this by adding a "nomobile" cookie when user clicks on "View Full Site" link which will be validated and negated by the rule. For some reason my rule doesn't seems to work. Please help.
<rewrite>
<rules>
<rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
</conditions>
<action type="Redirect" url="http://m.mymobilesite.com" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
IIS7 urlrewrite
Rovastar
3324 Posts
MVP
Moderator
Re: URL rewrite for Mobile/Cell phone devices
Nov 07, 2012 11:43 AM|LINK
The easiest way is to through it the failed request tracing.
http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
Dil
2 Posts
Re: URL rewrite for Mobile/Cell phone devices
Nov 08, 2012 09:26 PM|LINK