Forum Moderators: phranque

Message Too Old, No Replies

Rewrite everyone under a specific dir but one IP?

         

Siniz

5:11 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



I am new to this, but I have been checking around and started to learn some of the mod_rewrite options.

However, I ask kindly if you could help me with the following. How would I redirect everyone in a certain dir and all it's subdirectories, but one IP. That would be my IP. Is that possible?

Appreciate all input! Thanks

jdMorgan

6:34 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Siniz,

Welcome to WebmasterWorld!

You could use mod_rewrite's RewriteCond and RewriteRule directives to do this in two to four lines of code. We don't write code on request here, but our forum charter [webmasterworld.com] provides links to some basic references.

Jim

Siniz

8:45 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Thank you for the reply jdMorgan. I will try to figure it out myself and post here for help if I don't get it working. Thanks again.

Siniz

9:17 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Ok, I pretty much found out what to do I think, I am not sure if the syntax is right though. Basically, I want to rewrite everyone trying to access a special folder (that means all IP ranges) except my own.
I think it should looke something like this

RewriteCond %{REMOTE_ADDR} ^[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9] [AND]
RewriteCond %{REMOTE_ADDR} ^255.255.255.255 [] AND
RewriteCond %{REQUEST_URI}!^/images/
RewriteRule .* [whatever.com...]

There are a few things I want it to check. The first rewritecond should look for all ranges. The second rewritecond should be negative though, so if someone comes from 255.255.255.255, it shouldn't do the rule for him. The rule should rewrite anyone trying to go to the images dir and every subdir underneath it. It should rewrite to [whatever.com...]
One more cool thing would be if I could add a condition that said that if they went to a specific file under that dir (or subdir) they wouldn't be rewrited. Thanks :)