Forum Moderators: phranque

Message Too Old, No Replies

htaccess banning IP and redirect to some directories

htaccess redirection

         

paijan

4:44 am on Feb 23, 2004 (gmt 0)

10+ Year Member



Hi all, new here :)

I've been trying to redirect IP's using htaccess to some directories and pages but to no avail.

I do it using 403 error page. The line below only allow ban IP to visit otherpage.html but they cannot browse to other pages or directories since they are banned. What is the method to allow those banned IP to be able to visit certain pages and directories?

ErrorDocument 403 /otherpage.html

SetEnvIf Request_URI "(otherpage\.html¦robots\.txt)$" allowit
Order Deny,Allow
Deny from 000.00.00
Deny from 0.0000.00
Allow from env=allowit

Your answer would be higly appreciated

Thanks

:)

jdMorgan

6:25 am on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



paijan,

Welcome to WebmasterWorld [webmasterworld.com]!

The usual method to redirect based on IP address or user-agent, or other HTTP-Request variables is to use Apache mod_rewrite. The RewriteCond directive can test %{REMOTE_ADDR} and cause RewriteRule to redirect specific URI request to specific files if the IP address matches or is within a specified range.

403-Forbidden error handling should not be used for any intermediate purposes, or unexpected and possibly damaging side-effects can occur.

Introduction to mod_rewrite [webmasterworld.com]

Jim

paijan

7:18 am on Feb 23, 2004 (gmt 0)

10+ Year Member



Hi

Thanks for the welcome jim. I have looked at the page. great resource!

btw, I've modified my htaccess to smething like this, this is to allow some pages and directories being able to be seen by banned IP's

ErrorDocument 403 /otherpage.html

SetEnvIf Request_URI "(alloweddir/other.html¦otherpage\.html¦robots\.txt)$" allowit
Order Deny,Allow
Deny from 000.00.00
Deny from 0.0000.00
Allow from env=allowit

is this method correct?

Thanks :)

paijan

7:24 am on Feb 23, 2004 (gmt 0)

10+ Year Member



hhmm wait can this other method would work?

I banned the IP from the root directory using this code in htaccess

ErrorDocument 403 /otherpage.html

SetEnvIf Request_URI "(otherpage\.html¦robots\.txt)$" allowit
Order Deny,Allow
Deny from 000.00.00
Deny from 0.0000.00
Allow from env=allowit

then in the subectories where I would like the banned IP's also being able to see the page and sub directories, I would put another htaccess file which would allow all IP's

<Limit GET>
order allow,deny
allow from all
</Limit>

would this method will works?

Thanks

paijan

9:48 am on Feb 23, 2004 (gmt 0)

10+ Year Member



hhhmmm I was able to redirect to the page I want, but could get into the directories I wanted using two method above. Any opinion from you guys?

Thanks

paijan

11:19 am on Feb 23, 2004 (gmt 0)

10+ Year Member



Hi It's still me

Basically I want some IP redirected to certain page and being able to access view images from the page which is located in another directory (in this case /imagedir/subdir/)

This line seems not working either :(

SetEnvIf Request_URI "(allowed\.html¦robots\.txt)$" allowpage
SetEnvIf SPECIAL_PATH "(/imagedir/subdir/)$" allowdir
Order Deny,Allow
Deny from 202.146.241
Deny from 61.94.8.190
Allow from env=allowpage
Allow from env=allowdir

What's the correct way to do it?

jdMorgan

4:36 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



paijan,

You may want to use Referer or another Request_URI, I'm not sure.

 SetEnvIf Referer "/imagedir/subdir/$" allowdir 

Jim

paijan

5:18 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



Hi Jim thanks for the reply

But that seems cannot work either :(
I tried the whole server path btw

SetEnvIf Referer "www\.mydomain\.com/images/$" allowdir

Is there any method to overcome this?

Thanks

jdMorgan

11:20 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem here is likely to be in the details.

This code

 SetEnvIf Referer "/images/$" allowdir 

will allow referers from the only the index page in directory "/images/"

You may want to try:

 SetEnvIf Referer "http://www\.example\.com/images/" allowdir 

That will all images requested by any page in the /images directory to be displayed.

Jim

paijan

9:34 am on Feb 24, 2004 (gmt 0)

10+ Year Member



thanks Jim

Unfortunately that doesn't seems to work either :(

Gorufu

1:43 pm on Feb 24, 2004 (gmt 0)

10+ Year Member



The line below only allow ban IP to visit otherpage.html but they cannot browse to other pages or directories since they are banned. What is the method to allow those banned IP to be able to visit certain pages and directories?

.htaccess in a sub-directory overrides .htaccess in the / directory. Create a sub-directory for the 403 page and set it to allow from all

.htaccess in / directory
---------------------------------
ErrorDocument 403 /errorpages/403.html

order allow,deny
allow from all
deny from 1.2.3.4
deny from 5.6.7.8

.htaccess in errorpages directory
-----------------------------------
order deny,allow
allow from all

paijan

2:09 pm on Feb 24, 2004 (gmt 0)

10+ Year Member



Exactly what I Need !

Thanks Gorufu, Thanks Jim :)