gnznroses Posted February 8, 2012 Share Posted February 8, 2012 I have a rewrite to make mydomain.com/123 load the script at mydomain.com/links.php?id=123 links.php generates html with some links on the page. the links are supposed to have the referring url appended to them in the query string ( eg http://whatever.com/s.php?ref=<?=$_SERVER['HTTP_REFERER'];?> ), but it's always blank no matter what. would the rewrite cause HTTP_REFERER to be blanked out? what else might cause this? RewriteEngine on Options +FollowSymlinks RewriteCond %{HTTP_HOST} ^www\.mydomain.com [NC] RewriteRule ^(.*) http://mydomain.com/$1 [L,R=301] RewriteCond %{REQUEST_URI} !^/$ RewriteCond %{REQUEST_URI} !^/links\.php RewriteCond %{REQUEST_URI} !^/robots\.txt RewriteRule ^(.*)$ links.php?id=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/256637-referring-url-blanked-by-mod_rewrite/ Share on other sites More sharing options...
AyKay47 Posted February 8, 2012 Share Posted February 8, 2012 1. you should make your rewrite rule's regex tighter, I'm assuming that id can only be an integer, set that in your regex by using am int range, right now it will except anything... links.php/heythisisareallylongURIandisdefinitelynotavalidid the above will pass. 2. Have you actually checked to see if HTTP_REFERER is set in $_SERVER? if(isset($_SERVER['HTTP_REFERER'])) echo $SERVER['HTTP_REFERER']; else echo "element not set!"; Quote Link to comment https://forums.phpfreaks.com/topic/256637-referring-url-blanked-by-mod_rewrite/#findComment-1315670 Share on other sites More sharing options...
gnznroses Posted February 8, 2012 Author Share Posted February 8, 2012 oh i actually do need to accept any kind of character and not just an integer $SERVER['HTTP_REFERER'] is not set at all and hmm, oddly enough, if i follow a link to the "real" url, mydomain.com/links.php?id=123 it's still not set even if i go to pastehtml.com and enter a link to the page, then click that. it should have a referer either from the click or just the fact that it's i-framed (which i believe always sets the referer as the parent page) Quote Link to comment https://forums.phpfreaks.com/topic/256637-referring-url-blanked-by-mod_rewrite/#findComment-1315674 Share on other sites More sharing options...
AyKay47 Posted February 8, 2012 Share Posted February 8, 2012 $SERVER['HTTP_REFERER'] is not set at all Err in my code above. Should echo $_SERVER['HTTP_REFERER'] instead of $SERVER... This element is dependent on the browser which sends the http_referrer data, it is not always set, and can also be modified so it should not be trusted. Quote Link to comment https://forums.phpfreaks.com/topic/256637-referring-url-blanked-by-mod_rewrite/#findComment-1315677 Share on other sites More sharing options...
gnznroses Posted February 8, 2012 Author Share Posted February 8, 2012 ah, yeah and i just blindly copied it lol. but result is the same since the "If" line doesn't have the error. i guess my problem isn't a real problem, it's just that referrers aren't being passed in situations that i would expect them to. for example on pastehtml, i don't see why they're not. if you create a page with just a link to google.com for example, and use LiveHTTPHeaders to look at the headers when you click it, no Referer is being passed. not sure why. so i set up a test page on a domain of mine and tested with both a link and an iframe from there and it gets passed both times. and works as it should in my script. so it's not a mod_rewrite or apache problem appreciate the help man Quote Link to comment https://forums.phpfreaks.com/topic/256637-referring-url-blanked-by-mod_rewrite/#findComment-1315683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.