Forum Moderators: phranque
I am kinda new to Apache http server. Recently I am trying to implement a redirection rule base on the clients IP address. My problem is that even if for example I commented a RewriteCond line that corresponds to an IP address subnet the server still redirects the clients belonging to that subnet. Below is the rewrite rules I have added at the bottom of my httpd.conf. Kindly advise on what might be causing this problem.I believe this must have been a syntax error in my config.
RewriteEngine on
RewriteLog /root/apache.log
RewriteLogLevel 9
#RewriteCond %{REMOTE_ADDR} ^10\.85\. [OR]
#Dubai IP
RewriteCond %{REMOTE_ADDR} ^10\.80\.0\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.1\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.2\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.3\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.80\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.9\.1[0-9] [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.9\.2[0-5] [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.[1-6][0-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.7[0-2]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.120\.[1-9] [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.120\.[1-2][0-9] [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.120\.30 [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.12[8-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.13[2-8]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.14[4-8]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.1[5-9[0-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.2[0-2[0-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.23[0-2]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.23[4-5]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.80\.24[8-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.81\.[0-7]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.81\.12[8-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.81\.13[0-5]\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.8[2-3]\.$
RewriteRule ^(.*)$ http://86.96.**.68:2546/iptv/clients/online1/amino1/index.html
By the way, I am using the apache server which came with fedora 2, I know it's too old but you know what they say "You should fix what is not broken".
Thanks in advance
[edited by: jdMorgan at 2:26 pm (utc) on Dec. 8, 2009]
[edit reason] Obscured & de-linked target IP address. [/edit]
If you're testing using your own browser and IP address, be sure to completely-flush (delete) your browser cache after making any changes to any server-side code.
If you're testing by observing requests from IP addresses outside of your own, then the problem may be that you're on one of those 'funky hosts' that alias your .htaccess code to a different location and run it from there, but only copy the .htaccess files that you upload to that execution location on a periodic basis -- that is, after some appreciable delay.
As an aside, do be sure to take advantage of the power of regular-expressions to keep this code as small as possible. It's not 'too big' now, but as it grows, you'll want to make it as efficient as possible. For example, the first four RewriteConds can be reduced to
RewriteCond %{REMOTE_ADDR} ^10\.80\.[0-3]\. [OR] A later section can be reduced to
RewriteCond %{REMOTE_ADDR} ^10\.80\.23[0124589]\. [OR] If that redirect target address is on your own site, you'll also need to exclude it from the rule to prevent an 'infinite' redirection loop. And if not, you're simply 'passing on' the problem and tying up additional internet resources with that redirect; Consider changing the rule to just return a 403 and be done with it:
RewriteRule ^(.*)$ - [F] If you insist on redirecting these requests, you should add [R=302,L] to the end of your rule.
Jim
Thanks for the reply. Actually the Apache server is installed on a Fedora2 linux and is used as web portal for IPTV set-top boxes. All configuration of the Apache server is default and we just extracted the html pages to /var/www/html/ so the set-top boxes access the portal simply by using [ip-address...] Recently, we implemented a new web portal installed on a different server for the same reason we needed to redirect incoming connection from the current fedora2/apache server to these new portal. The redirection is base on the IP addresses of certain locations and rest will still be connecting to the old portal (note that we cannot change the url configuration of the web browser on the set-top boxes) and in case a problem arises we would like to cancel the redirection for the specific problematic IP addresses simply by commenting out the RewriteCond line. This is the reason why we needed a RewriteCond line of IP Addresses for each locations.
I will try adding [R=302,L] on the RewriteRule tomorrow and I will give you a feed back.
I am not sure if the browser of the set-top boxes are caching the old site so I will also have a look at that.
Best regards,
Ferdinand