How to forbid other people to access the page

i hava a site,in which root directory,there is a file hactess,now i want to forbid other people to access a page(eg:hello.php) of my site,but i can access it.how i can get this.someone told me to set only my IP can available the hello.php,but i don’t know how to do it.or there are any better ways to achieve this,any tips would be appreciated.

Welcome back, RED!

Check the tutorial and look for {REMOTE_ADDR}. What you want to do is to use a RewriteCond to examine the %{REMOTE_ADDR} of the visitor then use a RewriteRule to match the protected script’s name and redirect to … wherever.

Regards,

DK

whew,u have a good memory,thank you very much,i have read your tutorial.and if my IP address is 180.56.12.23,whether the code wrote as following?

RewriteEngine on
RewriteCond %{HTTP_HOST} !^…$ [NC]
RewriteCond %{REMOTE_ADDR} !^180\.56\.12\.23$
RewriteRule ^private - [F]

i am sorry,i can’t wrote this line— RewriteCond %{HTTP_HOST} !^…$ [NC].
because i want to ban all iPaddress.

RED,

Rather than quote your code, please use the [ code ] brackets as quote does not appear in message responses. Thank you.

RewriteEngine on
# RewriteCond %{HTTP_HOST} !^.........$ [NC] => unnecessary
RewriteCond %{REMOTE_ADDR} !^180\\.56\\.12\\.23$
RewriteRule ^private - [F]
# this implies that the directory or filename must start with private
# if that's the case, you get a gold star for a correct solution
# (after removing the first RewriteCond)

I believe that you should also use a Last flag with the Fail flag, though, i.e., [F] => [F,L].

Regards,

DK

thanks for U tips. i know the command RewriteCond is used to define a rule condition,there maybe one or many RewriteCond lines before the RewriteRule, the grammar of RewriteCond is: RewriteCond TestString CondPattern [flags].
i am also cofused about these line,
RewriteCond %{REMOTE_ADDR} !^180\.56\.12\.23$
RewriteRule ^private - [F]

does the two lines forbid everyone to access my site? am i right,but i only want to forbid everyone except me to access a subpage of my site.

You could use:

<Files "hello.php">
Order Allow,Deny
Deny from All
</Files>

And you can still acess your file by ftp.

Actually, you would HAVE to access your file by FTP as you would not be able to via HTTP!

Best to use a password protection system on the file or directory which needs protection but the IP Address exclusion from a ban (Fail) is the second best option (IMHO).

Regards,

DK

thanks to all your replies,but this answer isn’t i want,because i can’t access the file via HTTP! the result i want like the following,
eg:if anyone access the hello.php,he will get


Forbidden
You don't have permission to access /hello.php on this server.

but i can access the hello.php normally via HTTP and FTP!

RED,

The allow,deny method does not differentiate between you and other visitors (although it could allow from 180.56.12.23).

As per PM and Skype, using the IP address to access the hello.php script (and ban it for everyone else) is highly unreliable. Others who share your IP address WILL be able to access your script AND IP address can be spoofed (although I don’t know how to do that - I’m NOT a hacker).

IMHO, you’re far better off by employing Apache’s username/password combination (normally provided by cPanel calling it “Protect Directory”) OR by using a PHP login built into the script to limit access to you via username and password (I like this one most and employ a modification for many client websites).

Regards,

DK