Welcome to WebmasterWorld Guest from 34.236.216.93

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

How can send http_referer data to a script with htaccess?

     
5:27 am on Jun 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


to send a file to a script with htaccess, youd use
RewriteRule ^(.*)\.ext$ r.php?a=$1.ext

how can you send the referrer to a script as well?
to r.php?b=HTTP_REFERER

5:36 am on June 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


vaxop,

I'm no PHP expert, but the HTTP_REFERER variable is always available to scripts - It is one of many server environment variables, all accessible from within PHP, PERL, etc. You should not need to do anything outside of your script to access it.

Jim

5:42 am on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


ive tried..
but some servers dont send it

one server the $HTTP_REFERER variable works fine, on another, $HTTP_REFERER is empty

so im hoping theres a way to send it with htaccess

4:52 pm on June 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


vaxop,

Hmmm... Strange. This may have to do with the version you are using, and with its server variable format.

Oh well, here's a patch:


RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.ext$ r.php?a=$1.ext&b=%1

The %1 back-references the parenthesized sub-expression in the RewriteCond, in the same way that $1 back-references the subexpression in the RewriteRule itself.

HTH,
Jim

6:15 pm on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


thanks :)

how can you redirect multiple extensions?

RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.ext$ r.php?a=$1.ext&b=%1

id like to redirect wmv,mov,mpg :)

6:27 pm on June 23, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:July 16, 2001
posts:545
votes: 0


One of your servers may have register globals disabled. If that's the case, you wouldn't get any variables directly(for security reasons). Look through the $_SERVER[] array and see if it's in there.
6:28 pm on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


its strange.. left click seems to send the referrer properly, right click will not.. what could be causing it?

also,
do you know how to redirect multiple extensions?

RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.ext$ r.php?a=$1.ext&b=%1

id like to redirect wmv,mov,mpg :)

6:46 pm on June 23, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:July 16, 2001
posts:545
votes: 0


It might just be a "feature" of the browser.
6:49 pm on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


no.. it works fine on another server
7:26 pm on June 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


vaxop,

I can't answer your question about right-click. It has nothing to do with mod_rewrite, though. mod_rewrite sees only resource requests, it doesn't know or care how the request was invoked. It must be some other issue.

multiple filetypes:


RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.(wmvmovmpg)$ /r.php?a=$1.$2&b=%1 [L]

You will have to edit the broken vertical pipe "" characters, and change them to solid vertical pipes.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

7:49 pm on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


that doesnt seem to work..
i even tried replacing /r.php with r.php

when i access test.mpg, the file loads and not r.php

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.(wmvmovmpg)$ r.php?a=$1.$2&b=%1 [L]

8:02 pm on June 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


vaxop,

You'll need to flush your browser cache if you have loaded that file before adding the RewriteRule.

Jim

8:13 pm on June 23, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:May 18, 2003
posts:41
votes: 0


i have.. ive even tried it on another browser

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.(wmvmovmpg)$ r.php?a=$1.$2&b=%1 [L]

when accessing test.mpg, it loads test.mpg and not r.php?a=test.mpg&b=

on the other hand
RewriteEngine on
RewriteRule ^(.*)\.mpg$ r.php?a=$1.mpg [L]

works fine

9:17 pm on June 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Hmmm...

Perhaps an overly-greedy ".*" ?

Try this variant:


RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^([^\.]*)\.(wmvmovmpg)$ /r.php?a=$1.$2&b=%1 [L]

Edit the pipes as before. If that doesn't work, I have no idea...

Jim