<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>webdirect.no &#187; rewrite</title>
	<atom:link href="http://webdirect.no/tag/rewrite/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdirect.no</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jan 2009 20:26:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Apache rewrite rule for iPhone users</title>
		<link>http://webdirect.no/mobile/apache-rewrite-rule-for-iphone-users/</link>
		<comments>http://webdirect.no/mobile/apache-rewrite-rule-for-iphone-users/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 20:25:26 +0000</pubDate>
		<dc:creator>Morten Jacobsen</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://webdirect.no/?p=40</guid>
		<description><![CDATA[Like so many others these days I am preparing some of my web pages for iPhone invation. I am using this Apache rewrite rule only on the top level domain to route users to their optimized version. When you visit one of these versions, they are all accessable from any device. This is also what [...]]]></description>
			<content:encoded><![CDATA[<p>Like so many others these days I am preparing some of my web pages for iPhone invation. I am using this Apache rewrite rule only on the top level domain to route users to their optimized version. When you visit one of these versions, they are all accessable from any device. This is also what Apple recommends. </p>
<p><a href="http://www.flickr.com/photos/33215455@N00/1168912199/" title="Free Apple Desktop" target="_blank"><img src="http://farm2.static.flickr.com/1197/1168912199_dfe9578556.jpg" alt="Free Apple Desktop" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://webdirect.no/wp-content/plugins/photo_dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/33215455@N00/1168912199/" title="CAVE CANEM" target="_blank">CAVE CANEM</a></small></p>
<p>
Here is my Apache rewrite rule that I use to</p>
<ol>
<li>check if its an iPhone, redirect to optimized version</li>
<li>Identify the most common browsers by User Agent and redirect them to web version</li>
<li>redirect all others to mobile version</li>
</ol>
<h3>Rewrite rule</h3>
<pre>
<VirtualHost *:80>
ServerName www.mydomain.no

# This enables rewriting in this directory
RewriteEngine On

# Catch iPhone-users first, easiest to discover
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^[\./](.*)$ http://beta.mydomain.no/iphone  [L]

# Catch most familiar web browsers and redirect to web version,
# except Opera Mini and SymbianOS (which identifies itself as Safari)
RewriteCond %{HTTP_USER_AGENT} ((.*MSIE.*Windows\ NT.*)| \
  (Lynx.*)|(.*Safari.*)|(.*Opera.*)|(.*Firefox.*)|(.*Konqueror.*))
RewriteCond %{HTTP_USER_AGENT} !(.*Opera\ Mini.*)
RewriteCond %{HTTP_USER_AGENT} !(.*SymbianOS.*)
RewriteRule ^[\./](.*)$ http://beta.mydomain.no/web  [L]

# Browsers that match neither block, such as regular screen
# browsers, could be caught by a final rewrite rule placed here,
# or we could leave it out and have nothing happen to the
# requested URL. This is the default.

RewriteRule ^[\./](.*)$ http://beta.mydomain.no/mobile  [L]
</VirtualHost>
</pre>
<p>
Notice that it doesn&#8217;t sniff for &#8220;iPhone&#8221;, but &#8220;Mobile Safari&#8221;. This makes also iPod Touch compatible, which currently is the only device using the same browser.
</p>
<h3>Alternative rewrite rule</h3>
<p>This is the old rewrite rule that I used. This should only be used as a starting grid for further development. The WAP-test is not optimal, seems like Nokia&#8217;s and Sony Ericsson&#8217;s latest browsers get identified as ordinary web browsers without WAP-support and as a result gets redirected to the web version.</p>
<p>This set of rules where:</p>
<ol>
<li>check if its an iPhone, redirect to optimized version</li>
<li>check if it doesn&#8217;t support WAP, redirect to web version</strike></li>
<li>redirect all others to mobile version</li>
</ol>
<pre>
<VirtualHost *:80>
ServerName mydomain.no

# This enables rewriting in this directory
RewriteEngine On

# Catch iPhone-users first, easiest to discover
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^[\./](.*)$ http://beta.mydomain.no/iphone  [L]

# Catch XHTML MP browsers first and return XHTML MP content to them
RewriteCond %{HTTP_ACCEPT} !text/vnd\.wap\.wml
RewriteRule ^[\./](.*)$ http://beta.mydomain.no/web  [L]

# Browsers that match neither block, such as regular screen
# browsers, could be caught by a final rewrite rule placed here,
# or we could leave it out and have nothing happen to the
# requested URL. This is the default.

RewriteRule ^[\./](.*)$ http://beta.mydomain.no/mobile  [L]
</VirtualHost>
</pre>
<p>
Please leave a comment if you see or have a smarter way of doing this.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdirect.no/mobile/apache-rewrite-rule-for-iphone-users/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

