views:

42

answers:

2

I'm trying to parse hostname only from the Apache server variable HTTP_REFERER and I'm wondering if it's possible with mod_rewrite since my goal is to obtain the hostname and then rewrite the request.

A: 

Your HTTP_REFERER will return the exactly URL that linked to your page, with mode_rewrite or not, it will return the literal url. So, if it is something.com/foo/index.php or somthing.com/foo/action, the http_referer will cat these urls like as appear.

Keyne
I Knew that much, my problem was the whole referrer URL was wreaking havoc on a client-side element. Since I didn't need the whole URL and the hostname alone was safe, I tried to parse it out.
John Giotta
A: 

I figured it out

RewriteCond %{HTTP_REFERER} ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? [NC]
RewriteRule ^traveler.html$ http://something.com/viewer.html?embed_referer=%4 [QSA,L]

With the back-reference from RewriteCond, I can append the query string to the new path/URL.

John Giotta