LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2009, 01:57 AM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
Doubt about RewriteCond?


Just had a few doubt regarding this one.I need help with apache RewriteCond stuff:

Code:
RewriteCond   %{HTTP_ADDR}   !217.220.[32-47]  
RewriteCond   %{HTTP_ADDR}   !217.220.[32][0-27]
All I need to know whats the above line means?
How can I add 217.220.32/27 to this list?
 
Old 12-18-2009, 02:34 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502
Hi,

There is no variable HTTP_ADDR. Maybe you mean the REMOTE_ADDR variable.
Quote:
RewriteCond %{HTTP_ADDR} !217.220.[32-47]
RewriteCond %{HTTP_ADDR} !217.220.[32][0-27]
The 2nd does not make sense, the first means all the subnets that are not in the range from 217.220.32.0/24 to 217.220.47.0/24.
Also it's better to include the IPs inside ^ and $ so they are not ambiguous. So in your case, use:
Code:
RewriteCond %{REMOTE_ADDR}       !^217.220.[32-47]$
RewriteCond %{REMOTE_ADDR}       !^217.220.32.\/27$
Regards
 
Old 12-18-2009, 02:51 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
Rep: Reputation: 51
My Client has provided me with: 217.220.32.120/27?
Code:
How can I add 217.220.32.120/27 to this list?
 
Old 12-18-2009, 02:57 AM   #4
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
Rep: Reputation: 51
I am sorry for the entry
Code:
 %{HTTP_ADDR}
Also, What does this mean?
Code:
RewriteCond %{REMOTE_ADDR}       !^217.220.32.\/27$
I am sorry I miswrote the following first line:
Code:
RewriteCond %{HTTP_ADDR} !217.220.120.[32-47]
What if I wrote

RewriteCond %{HTTP_ADDR} !217.220.120.[32][0-27]
Is this correct entry for 217.220.120.32/27?

Last edited by your_shadow03; 12-18-2009 at 03:09 AM.
 
Old 12-18-2009, 03:11 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502
Quote:
My Client has provided me with: 217.220.32.120/27?
Are you sure about that, because according to the subnet calculator the valid ips are 217.220.32.97 to 217.220.32.126.
If that's the case use either one of the following:
Code:
RewriteCond %{REMOTE_ADDR}       !^217.220.32.[97-126]$
RewriteCond %{REMOTE_ADDR}       !^217.220.32.120\/27$
Quote:
Also, What does this mean?
Code:

RewriteCond %{REMOTE_ADDR} !^217.220.32.\/27$
Means that the remote_addr is not in the subnet 217.220.32/27 (what you asked in your 1st post). The backslash "\" just escapes the forward slash "/"
 
Old 12-18-2009, 03:18 AM   #6
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Sorry for wrong IP.
The correct one was:

217.72.112.32/27
Can yu suggest for the same?
 
Old 12-18-2009, 08:33 AM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502
In that case use the following.
Code:
RewriteCond %{REMOTE_ADDR}       !^217.72.112.[33-62]$
I've removed the 2nd option, as I haven't found any examples using subnet notation in mod_rewrite, so I don't know if it really works.
 
Old 12-18-2009, 01:05 PM   #8
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Thanks.
I tried using:
Code:
RewriteCond %{REMOTE_ADDR}       !217.72.112.32[0-27]
And it worked!!!
Surprisingly!!!
But I do recommend client using what you suggested !!
 
Old 12-18-2009, 04:29 PM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502Reputation: 1502
Are you sure it's working?
Because your condition will match for IPs not in the range 217.72.112.320 to 217.72.112.3227. Since these IPs do not exist actually, it will match any other host!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct Apache RewriteCond to stop proxying ... curtisa Linux - Security 1 07-21-2009 11:38 AM
One doubt please .. vibinlakshman Slackware 1 02-18-2009 08:57 PM
RewriteCond & Rewrite Rule Problemo sea-bass Linux - Server 0 04-07-2008 11:44 AM
Doubt in C++ zeropash Programming 1 07-05-2005 01:33 PM
DOUBT .- jordomi Linux - Distributions 2 08-23-2000 07:53 AM


All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration