HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Server Operation (http://www.howtoforge.com/forums/forumdisplay.php?f=5)
-   -   Redirect all except one /24 to another URL (http://www.howtoforge.com/forums/showthread.php?t=59725)

forrie 28th November 2012 23:37

Redirect all except one /24 to another URL
 
I'm having a devil of a time getting Apache's Rewrite* stuff to do what I need.

Basically, I have a range of IP space that I need to redirect to a specific URL /except/ one IP within that range. Everyone else in the world also gets the normal/default URL.

So, in pseudocode:

If matches all of 1.2.0.0 BUT NOT 1.2.3.4
Redirect to http://this.site
else
continue
Fi

Specifically I am also redirecting any queries to ^/ to a specific page (ie: index.php) but I need the above conditional to apply.

I've tried many examples from out there and it's understandably confusing. It appears you can't really negate this in a RewriteCond loop, either -- I tried it.

Anyone know how to accomplish this correctly in apache 2.2?


Thanks.

patrick3853 5th December 2012 22:09

By default multiple RewriteCond's are treated using a logical AND, so...

Code:

RewriteCond %{REMOTE_ADDR} ^1\.2\.
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule...

Does exactly what you want. It says If the IP starts with 1.2. and does not equal 1.2.3.4, then apply the rule


All times are GMT +2. The time now is 21:17.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.