Forum Moderators: phranque

Message Too Old, No Replies

How can send http_referer data to a script with htaccess?

         

vaxop

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

10+ Year Member



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

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



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

vaxop

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

10+ Year Member



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

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



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

vaxop

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

10+ Year Member



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

Slade

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

10+ Year Member



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.

vaxop

6:28 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



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

Slade

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

10+ Year Member



It might just be a "feature" of the browser.

vaxop

6:49 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



no.. it works fine on another server

jdMorgan

7:26 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 ^(.*)\.(wmv¦mov¦mpg)$ /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

vaxop

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

10+ Year Member



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 ^(.*)\.(wmv¦mov¦mpg)$ r.php?a=$1.$2&b=%1 [L]

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



vaxop,

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

Jim

vaxop

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

10+ Year Member



i have.. ive even tried it on another browser

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(.*)$
RewriteRule ^(.*)\.(wmv¦mov¦mpg)$ 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

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

Perhaps an overly-greedy ".*" ?

Try this variant:


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

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

Jim