How to get Redirected URL


I have a URL.when i try to open it in browser, it will redirect to another URL & display the Content. I want that content But i don't get that redirected URL. So, I can't able to display data.

How can i do that programmatically??

<strong>e.g. URL which i have :</strong> <a href="http://www.windpowerengineering.com/?p=11020" rel="nofollow">http://www.windpowerengineering.com/?p=11020</a>

<strong>& the redirected URL is:</strong> <a href="http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/" rel="nofollow">http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/</a>

<strong>I want this redirected URL</strong>. How can i get this?


1) Specify that your class conforms to the UIWebViewDelegate protocol (and make sure your WebView's delegate outlet is connected to your view controller):

@interface YourWebsiteViewController : UIViewController <UIWebViewDelegate>

2) Add the following delegate method:

-(void)webViewDidStartLoad:(UIWebView *)webView { NSURL *url = [webView.request mainDocumentURL]; NSLog(@"The Redirected URL is: %@", url); }

Depending on what you're trying to do with this information, you might want to substitute #2 for this method (which will allow you the opportunity to prevent a page from loading):

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request mainDocumentURL]; NSLog(@"The Redirected URL is: %@", url); // Return YES if you want to load the page, and NO if you don't. return NO; }


use javascript



Did you try this delegate method?

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

It will be called whenever the webview loads a webpage.

You can get the URL from one of this method's parameters, request

NSURL *regURL=[request URL]; NSString *urlString=[regURL absoluteString];


That URL is part of the http header. This is what happening:

request 1: <a href="http://www.windpowerengineering.com/?p=11020" rel="nofollow">http://www.windpowerengineering.com/?p=11020</a>

response 1: page has moved go to <a href="http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/" rel="nofollow">http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/</a>

and then your browser will go:

request 2: <a href="http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/" rel="nofollow">http://www.windpowerengineering.com/design/mechanical/blades/bladeless-turbine-converts-wind-into-fluid-power/</a>

response 3: here is the html

If you look at the http headers from response 1 you will be able to extract the url from the Location header. In Objective C this is one way to do it:

NSURLResponse* response = // the response, from somewhere NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields]; NSString* redirection_url = [headers objectForKey:@"Location"];

In the above code you can access all of the response http headers from the headers dictionary.


  • Segue with Push animation Right to Left
  • Adding padding and border to an UIImageView
  • Saving an array of NSURL to NSUserDefaults
  • UINavigationController alternatives
  • UITableView without still works!
  • Printing input from TextField to a Label in Xcode with Swift
  • How to clear out the contents of a map when clear() method call throws UnsupportedOperationException
  • what is browser's native support according to selenium webdriver
  • send data back from jsp iterator to struts action class
  • JOOQ nested condition
  • How to set the navigation bar to the top in Table View?
  • How can I create a plugin mechanism that calls functions only when the plugin is available?
  • How to accept a collection of a base type in WCF
  • Getting zero results in search using elastic4s
  • Does “internal” visibility modifier in Kotlin work yet?
  • How to get Fully qualified domain name in unix
  • Run script file on remote server
  • How to make stdcall from Go
  • Mercurial: Identify file name after rename
  • Why are “sc.addFile” and “spark-submit --files” not distributing a local file to all workers?
  • Comparing user's facebook/twitter friends to site's users in Python/Django
  • Receiver has no segue with identifier“***”
  • Why can't UI components be accessed from a backgroundworker?
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • ASP.NET MVC Application won't update some controllers
  • CakePHP ACL tutorial initDB function warnings
  • Firefox Extension - Monitor refresh and change of tab
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Avoid links criss cross / overlap in d3.js using force layout
  • Recording logins for password protected directories
  • Deselecting radio buttons while keeping the View Model in synch
  • Deleting and Updating values from a cusrsor adapter
  • C# - Serializing and deserializing static member
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • bootstrap to use multiple ng-app
  • Cannot Parse HTML Data Using Android / JSOUP
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • Binding checkboxes to object values in AngularJs
  • How to load view controller without button in storyboard?