I am attempting to restrict the use of a web page with mod_rewrite, in line with the referer. The webpage's URL is http://www.example.com/path/to/page.php It's situated on the Debian server in /var/www/path/to/page.php I've got a rewrite map -allowedReferers- that contains a listing of Web addresses

-allowedReferers

http://www.example.com/test/test1.php:white

http://www.example.com/test/test2.php:white

I additionally possess the following rewrite conditions/rules

RewriteCond % ^(.*)$

RewriteCond $black ^black$ [NC]

RewriteRule /* http://www.someotherplace.com [R,L]

To date this works perfectly well.

http://www.example.com/test/test1.php

http://www.example.com/test/test2.php

Can access the web site, while

http://www.example.com/test/test3.php

will get rerouted to someotherplace.com.

My issue is that, in tangible existence, my referers will contain GET parameters. e.g. http://www.example.com/test/test1.php?id=245

My idea ended up being to rewrite the very first condition to something similar to this

RewriteCond % ^(.)?.$

or this

RewriteCond % ^(.)?id=[-9]$

I have examined both regexes in Firefox' RegexTester plus they work as I would like these to. Put on the next input

http://www.example.com/test/test1.php?id=245

they return this for $1:

http://www.example.com/test/test1.php

I was expecting that %1 also consists of the URL without the GET parameters. To ensure that, departing the relaxation from the rule unchanged:

RewriteCond $black ^black$ [NC]

RewriteRule /* http://www.someotherplace.com [R,L]

should increase the risk for expected behavior:

http://www.example.com/test/test1.php?id=234

http://www.example.com/test/test2.php?id=222

can access the web site, while

http://www.example.com/test/test3.php?id=256

(or http://www.athirdplace.com/ etc.)

is going to be rerouted to someotherplace.com

Regrettably it doesn't work as expected whatsoever. Getting applied the modification towards the first condition all of a sudden every referer can access the web site.

When I desired to see what really is within %1, I emerged using the following idea:

RewriteCond % ^(.)?id=[-9]$

RewriteCond $black ^black$ [NC]

RewriteRule /* %1 [R,L]

Presuming that refering towards the page from

http://www.example.com/test/test2.php?id=234

would redirect me to

http://www.example.com/test/test2.php

Wrong assumption. it redirects me to http://www.example.com/var/www/path/to/ that is, when i pointed out at first, the address from the page whose access will be restricted. Not to mention brings about a 404, as /var/www/ is docroot.

??????????????????

Redirecting to %1 only agreed to be a desperate make an effort to debug my problem, so I don't need a strategy to accomplish this. What I am searching for is a method to solve my original redirection problem. Referers such as these

http://www.example.com/test/test1.php?id=234

http://www.example.com/test/test2.php?id=222

(whichever id is passed)

visit

http://www.example.com/path/to/page.php

while anything else would go to

http://www.someotherplace.com

Finally I'd also appreciate any ideas how you can debug mod_rewrite, especially methods to look into things like %, %1, $1, and so forth.

Thanks