Topic: Refering domain [SOLVED]

Im tring to figure out how to do this...

Right now i have this in my code:

def refer
 r = request.env["HTTP_REFERER"]
 rdomain = ???
 ** some other non important code here

the value of "r" gives me something like: … b092c3cb09

However i want the value of "rdomain" to equal "" without the tailing information. How exactly would i do this?

Thanks in advance

Last edited by Arcadie (2011-04-19 16:55:11)

Re: Refering domain [SOLVED]

Figured a way to do this...
Lets say you have this url for example:
and you want to get just the referring domain of

here is how I did it

def find_refering_domain
  referring_url = request.env["HTTP_REFERER"]
  referring_domain = refering_url.gsub("http://", "").gsub("https://", "").gsub("www.", "").gsub("/", "#").gsub(/#.*$/, "")

Im sure there is a little more efficient way but this works.
It must go in this order and heres that it all does.

The first 2 gsubs turn this:
into this:

The third turns this:
into this:

The four turns this:

and the last turns this:
into this:

The reason i turned "/" into "#" is because i could not find the code to gsub / + everything behind it, but i did find a way to do # plus everything behind that.