Since on an iPad we cannot edit the hosts file (without jailbreaking), how can we arbitrarily redirect web traffic to another url?
This would be important for something such as developing a website that uses a Virtual Host configuration where you want to redirect to a development machine.
(This is related to this question: Can I edit an iPad's host file?)
Setup the hosts file on a computer running a proxy server such as Fiddler or Charles, and configure the iPad to use that computer as an HTTP proxy.
Here are instructions for how to do this with Fiddler: http://conceptdev.blogspot.com/2009/01/monitoring-iphone-web-traffic-with.html
And this is for Charles: http://www.ravelrumba.com/blog/ipad-http-debugging/
The way to get around this limitation of the iPad is to use a HTTP proxy server, such as Squid running on another machine where you can edit the hosts file.
On the iPad Under Settings -> Network -> Wi-Fi -> (Your network) There is a HTTP Proxy setting which can be set to manual. Enter you proxy information here.
Once this is set up you would be able to manipulate the iPad as if you were changing the hosts file.
Internal DNS Server is one of the option but that was too cumbersome to implement. We tried installing squid as proxy server but that also didnt work because it was redirecting the URL to new server and this redirection was seen on browser URL too.
Thing which finally worked for us was to install Fiddler on one of the server and use this server as the proxy server on ipad. Fiddler also has a feature to map sub-domains to IP address i.e. something similar to /etc/hosts.
Nice tutorial to do so: http://egalo.com/2012/05/29/testing-mac-web-site-using-local-hostname-on-mobile-device/
An other way is to connect the IPad via Local Hotspot with my MAC OS X and establish an port-forwarding to the development VM. To achieve this I'v done the following Steps:
ssh -NL <IP-of-hotspot-host>:<source-port>:<url-to-local-vm>:80 <user-to-vm>
<IP-of-hotspot-host>:<source-port>
Where to get 'IP-of-hotspot-host':
After created hotspot there is a WLAN-Point in
MAC OS X system settings >> Network >> WLAN
Adding the ServerAlias:
At my development-VM (Apache2) in /etc/apache2/sites-available/dkr.dev.local I had to add the following:
I would try Relay Server (part of Afaria) which can re-direct mobile traffic based on profiles.
Update: tremoloqui's answer seems less trouble and far cheaper.
It's also possible to use Weblock - AdBlock for iOS app (available for $1.99 here: https://itunes.apple.com/us/app/weblock/id558818638?mt=8) to create web traffic redirects.
This allows you to redirect any traffic matching certain rule to specified IP address. This will emulate adding an entry to /etc/hosts on your iOS device. If the hostname set in requests is handled by the IP you direct your traffic to, you can use this to test private API or even sniff traffic sent from other apps or websites. This unfortunately works only for http/https connections.
All this can be done only while on Wi-Fi (one of Weblock's limitations). There main advantage is that you can easily configure everything from your iOS device and there is no need to mess with DNS/proxy server configuration.
Here's an example:
Weblock is also good to selectively redirect some URL's with regular expressions. You could redirect queries to certain endpoint only, while all other queries go to the IP returned from the DNS. This actually allows for even more fitting configuration that /etc/hosts does.
Example: If I create a URL redirect rule for htt*://somedomain.com/api/login* and some IP and port, I will see only traffic from this URL at this IP and port, while all other traffic to somedomain.com will go directly to the IP returned by the DNS. Notice it will work for both /api/login and /api/login?someparam=somevalue thanks to the wildcard * sign at the end of the rule.