Page 1 of 1

send specific visitor (IP) a special page?

Posted: Wed May 30, 2012 7:38 am
by wvoyance
I know I can block some specific IP by
order allow,deny
deny from 210.242.215.197/32
allow from all

But could I send them a specific page?
Those visitors are really nuscent I want to tell them do not come again. :roll:

Re: send specific visitor (IP) a special page?

Posted: Wed May 30, 2012 8:08 am
by Celauran
Why not use a PHP header redirect?

Code: Select all

header('Location: foo');

Re: send specific visitor (IP) a special page?

Posted: Wed May 30, 2012 10:18 am
by wvoyance
Celauran wrote:Why not use a PHP header redirect?

Code: Select all

header('Location: foo');
Then, they can still access other pages, to my understanding.

Re: send specific visitor (IP) a special page?

Posted: Wed May 30, 2012 10:33 am
by Celauran
Not necessarily. You can easily put the blacklist code in one of your included files or your front controller, depending on how your site is set up. In either scenario, every request will see this code called and the undesirables redirected away. Unless, of course, they come in through a proxy of some sort.

Re: send specific visitor (IP) a special page?

Posted: Thu May 31, 2012 6:44 am
by wvoyance
Celauran wrote:Why not use a PHP header redirect?

Code: Select all

header('Location: foo');
Could this command redirect only some visitor, not all?
I would like to redirect some visitor :P

Re: send specific visitor (IP) a special page?

Posted: Thu May 31, 2012 8:43 am
by Celauran
Well yes, of course. Wrap it in a conditional.

Re: send specific visitor (IP) a special page?

Posted: Fri Jun 08, 2012 9:34 am
by VladSun

Code: Select all

header('Location: foo');
exit(); // !!!!

Re: send specific visitor (IP) a special page?

Posted: Fri Jun 08, 2012 9:50 am
by pickle
I believe you can do it in mod_rewrite & therefore in your .htaccess file like your original post:

[syntax]RewriteCond %{REMOTE_HOST} ^210\.242\.215\.197
RewriteRule .* /offline.php [R=302,L][/syntax]

I'm not entirely sure how to do it with IP ranges though

Re: send specific visitor (IP) a special page?

Posted: Fri Jun 08, 2012 9:54 am
by Celauran
The problem with using .htaccess is that you'd need a new entry for each IP or CIDR value versus being able to query a database if you do it in PHP.

Re: send specific visitor (IP) a special page?

Posted: Fri Jun 08, 2012 7:43 pm
by wvoyance
Is every sub-directory which has an index.php need a .htaccess?

I put a .htaccess as the root directory but does not seems to be able to prevent access of some directories.
Put more .htaccess at those directories seems become o.k.
I found those directories seems all contain an index.php

Re: send specific visitor (IP) a special page?

Posted: Mon Jun 11, 2012 9:47 am
by pickle
No, an .htaccess file is supposed to be applied to every subdirectory. I'm not sure if there are Apache directives that can be changed which make .htaccess only apply to the current directory, but I've always had them apply to ancestor directories.