Is it possoble to obtain the hostname only from HTTP_REFERER with mod_rewrite?
I'm trying to parse hostname onl开发者_如何学Pythony 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.
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.
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.
精彩评论