Forum Moderators: phranque

Message Too Old, No Replies

htaccess calling php page in a loop

htaccess calling php page in a loop

         

phparion

12:21 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I want to block certain countries from visiting my site for this I have written a test.php page which test the ip of the user against a table and then take the decision whether to send the user to the site or back to the block message page...

I am using this htaccess code

Code:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI}!^.*test\.php.*$
RewriteRule ^(.*)$ test.php?var1=$1 [L]
</IfModule>

means, if the URL is not domain.com/test.php send the user to test.php page for checking his ip otherwise he is already checked for his ip and keep him on the page he wants to.

now when test.php page sends user back to the exact URL he puts to visit the page ($var1) the user is again redirected because the htaccess rule again matches and my RewriteCond doesn't work...

How can I prevent it from looping so that if a user is already checked for his IP he should not be checked again?

any help is highly appreciated...

jdMorgan

1:29 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you can use RewriteMaps (requires httpd.conf or conf.d server config access), you'll probably be happier if you simply call the IP check from each of your 'real' pages, which can then generate a 403-Forbidden response and suppress page-content generation if the IP address check fails.

Remember that an external redirect ends the current HTTP transaction and tells the client (browser or robot) to start a new one. Because of this, and because HTTP is a 'stateless' protocol, Apache will have no 'memory' of previous requests, and cannot 'know' that a second request is related to a first request. Therefore, access control must be accomplished completely within the context of a single HTTP request, meaning you cannot use an external redirect. You can use internal URL rewriting, as available in mod_rewrite, or you can include scripts and content conditionally, but no external redirects.

Jim

phparion

1:42 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thank you Jim.

my main problem is that currently all pages are .html and not .php so I can't include some snippet to check IP...

host doesn't have mod_geoip support otherwise it was piece of cake for me :)

however I do have complete geoIP binary file which has all the IPs in it and I can compare visitor's IP against it.

so what I have is geoIP db, all html pages, mod_rewrite enabled, htaccess working.. nothing beyond it..

what could be way out? I am stuck with it for the last five hours now :(

jdMorgan

2:04 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why don't you tell your server to parse html files [google.com] for php? -- Apache does not care what you name your files...

Jim

phparion

2:09 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i told this to my client before you said it but he refused it right a way because he thinks it will affect his SEO rank :)

jdMorgan

2:19 pm on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Piffle.

Jim