# Can we stop internal redirects

**URL:** <https://www.ruby-forum.com/t/can-we-stop-internal-redirects/172120>\
**Category:** Ruby\
**Created:** [July 15, 2009, 7:17am UTC](https://www.ruby-forum.com/t/can-we-stop-internal-redirects/172120 "2009-07-15T07:17:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbce88/32.png) [@newbie123](https://www.ruby-forum.com/u/newbie123)\
**Post date:** [July 15, 2009, 7:17am UTC](https://www.ruby-forum.com/t/can-we-stop-internal-redirects/172120/1 "2009-07-15T07:17:52Z")

</div>

Hi,  
I have been trying to write a ruby script using a mechanize library.  
There is an issue am not able to fix, which is internal re-directs.  
My script hits a link and that link re-directs to another link. I would  
like to control or stop that internal re-direct. Can this be done using  
mechanize or any other library?

Thanks

---

<div class="post-metadata">

**Author:** ![newbie123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbce88/32.png) [@newbie123](https://www.ruby-forum.com/u/newbie123)\
**Post date:** [July 15, 2009, 7:48am UTC](https://www.ruby-forum.com/t/can-we-stop-internal-redirects/172120/2 "2009-07-15T07:48:59Z")

</div>

On Tue, Jul 14, 2009 at 10:17 PM, Newbie Newbie  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Hi,  
> I have been trying to write a ruby script using a mechanize library.  
> There is an issue am not able to fix, which is internal re-directs.  
> My script hits a link and that link re-directs to another link. I would  
> like to control or stop that internal re-direct. Can this be done using  
> mechanize or any other library?

3 options depending on exactly what you desire

follow\_redirect? = false will turn off all redirects

this patch [http://geekchat.ru/node/93](http://geekchat.ru/node/93) shows how to limit the number of  
times  
it will follow a redirect if you are trying to stop some endless loop

use the patch above as the basis to modify the redirect concept to look  
at  
the uri to determine if it’s internal or not and stop on an internal (no  
code at hand but it would appear pretty straight forward since you have  
the  
original and redirect uri’s within the function for you).

John
