Jump to content

Referring URL blanked by mod_rewrite?


gnznroses

Recommended Posts

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]

Link to comment
Share on other sites

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!";

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.