I think you are looking at it wrong.
If you look on the Internet, find a site with a search function and follow the link, you will see a parameter showing what you were looking for.
This is a good way to do it.
Doing this HTTP_REFERER
seems a little fragile and will not work, for example, from a bookmark or hosted link.
eg.
/cars/12?from_search=sports+cars
then you can just look params[:from_search]
If you really need to do this with HTTP_REFERER
, you probably won't have to worry about subdomains. Just
def http_referer_uri request.env["HTTP_REFERER"] && URI.parse(request.env["HTTP_REFERER"]) end def refered_from_our_site? if uri = http_referer_uri uri.host == request.host end end def refered_from_a_search? if refered_from_our_site? http_referer_uri.try(:query)['search'] end end
source share