Forum Moderators: phranque

Message Too Old, No Replies

Rewriting help

         

Siniz

10:49 am on Jun 7, 2005 (gmt 0)

10+ Year Member



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 .* http://www.example.com/test/

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. (like!= in java or javascript). The rule should rewrite anyone trying to go to the images dir and every subdir underneath it. It should rewrite to http://www.example.com/test/.

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 :)

[edited by: jdMorgan at 2:35 am (utc) on June 8, 2005]
[edit reason] examplified [/edit]

ChadSEO

8:42 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Let me make sure I got this right. You want everyone attempting to access a certain folder (/images/ in this example) to be redirected, except you, based on your IP address (10.1.1.1 in my example). Additionally, if they try to access a particular file (/images/one_special_page.html in my example), they should not be redirected. Is this correct?

If so, you're probably looking for something like this:
RewriteCond %{REMOTE_ADDR} !^10.1.1.1 [AND]
RewriteCond %{REQUEST_URI} ^/images/ [AND]
RewriteCond %{REQUEST_URI} ~^/images/one_special_page.html
RewriteRule .* http://www.example.com/test/

[edited by: jdMorgan at 2:34 am (utc) on June 8, 2005]
[edit reason] examplified [/edit]

jdMorgan

2:23 am on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no such thing as an [AND] flag, so the code is invalid.

Also, it can be simplified down to two lines:


# redirect requests for /images folders and files unless from my IP address
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.1$
RewriteRule ^images/ http://www.example.com/test/ [R=301,L]

Put your own IP address in the RewriteCond line in place of 192.168.0.1, with the literal periods escaped as shown. As you noted, the "!" operator means "not"; the "=" is implicit.

Jim