Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 12-04-2012, 12:48 AM
vectro's Avatar
Contributing Member
 
Join Date: 12-29-08
Location: U.S.A.
Posts: 435
iTrader: 0 / 0%
Need .htaccess code to keep certain IP addresses off of one file only

I'm trying to use this code and it's not blocking the IP addresses. It's still allowing IPs from the specified ranges:

PHP Code:
<files submit.php>
order allow,deny
deny from 1.2.3
.
deny from 1.2.
allow from all
</files
What am I doing wrong and how to I correct it?

Last edited by snakeair; 12-04-2012 at 06:35 AM.
 
Reply With Quote
  #2 (permalink)  
Old 12-04-2012, 01:52 AM
hirithk's Avatar
Contributing Member
Latest Blog:
None

 
Join Date: 04-11-12
Posts: 190
iTrader: 0 / 0%
hi,
1.if you want to block one specific 3ip please follow the below code
order allow,deny
deny from 192.168.44.201
deny from 224.39.163.12
deny from 172.16.7.92
allow from all
2. if you want to block whole range of ip means
order allow,deny
deny from 192.168.
deny from 10.0.0.
allow from all
3. to block specific isp
order allow,deny
deny from some-evil-isp.com
deny from subdomain.another-evil-isp.com
allow from all
 
Reply With Quote
  #3 (permalink)  
Old 12-05-2012, 01:59 AM
Junior Member
 
Join Date: 10-29-06
Posts: 20
iTrader: 0 / 0%
Make sure your are entering this in your website's root .htaccess file and not in a directory.
 
Reply With Quote
  #4 (permalink)  
Old 12-05-2012, 04:54 PM
vectro's Avatar
Contributing Member
 
Join Date: 12-29-08
Location: U.S.A.
Posts: 435
iTrader: 0 / 0%
Quote:
Originally Posted by hirithk View Post
hi,
1.if you want to block one specific 3ip please follow the below code
order allow,deny
deny from 192.168.44.201
deny from 224.39.163.12
deny from 172.16.7.92
allow from all
2. if you want to block whole range of ip means
order allow,deny
deny from 192.168.
deny from 10.0.0.
allow from all
I already tried that exact sequence.

Quote:
Originally Posted by crispinblake View Post
Sometimes you just don't want a certain person (or bot) accessing your website at all. One simple way to block them is to ban their IP address:
order allow,deny
deny from IP
deny from IP
deny from 172.16.7.92
allow from all
See above.

Quote:
Originally Posted by nimonogi View Post
Make sure your are entering this in your website's root .htaccess file and not in a directory.
It is in the root.

The IPs are not being blocked. I have tried with and without <Files></Files>.
 
Reply With Quote
  #5 (permalink)  
Old 12-14-2012, 12:29 PM
vectro's Avatar
Contributing Member
 
Join Date: 12-29-08
Location: U.S.A.
Posts: 435
iTrader: 0 / 0%
I'm open minded to this being done with mod_rewrite instead of using 'deny from' if someone has a solution. It doesn't matter to me what code is used as a long as it does the trick and fits in .htaccess.
 
Reply With Quote
  #6 (permalink)  
Old 12-15-2012, 05:39 AM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 3,003
iTrader: 1 / 100%
Maybe this will help:
Code:
# block individual IPs <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.1 [OR] RewriteCond %{REMOTE_ADDR} ^456\.789\.123\.2 [OR] RewriteCond %{REMOTE_ADDR} ^789\.123\.456\.3 [OR] RewriteRule ^(.*)$ - [F,L] </IfModule> # block ranges of IPs <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REMOTE_ADDR} ^123\. [OR] RewriteCond %{REMOTE_ADDR} ^456\.789\. [OR] RewriteCond %{REMOTE_ADDR} ^789\.123\.456\. [OR] RewriteRule ^(.*)$ - [F,L] </IfModule> # alt block IP method <Limit GET POST PUT> order allow,deny allow from all deny from 123. deny from 123.456. deny from 123.456.789.0 </Limit>
Source: http://perishablepress.com/eight-way...s-mod_rewrite/
 
Reply With Quote
  #7 (permalink)  
Old 12-15-2012, 12:23 PM
vectro's Avatar
Contributing Member
 
Join Date: 12-29-08
Location: U.S.A.
Posts: 435
iTrader: 0 / 0%
Quote:
Originally Posted by J. H. Rasmussen View Post
Maybe this will help:
Code:
# block individual IPs <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.1 [OR] RewriteCond %{REMOTE_ADDR} ^456\.789\.123\.2 [OR] RewriteCond %{REMOTE_ADDR} ^789\.123\.456\.3 [OR] RewriteRule ^(.*)$ - [F,L] </IfModule> # block ranges of IPs <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REMOTE_ADDR} ^123\. [OR] RewriteCond %{REMOTE_ADDR} ^456\.789\. [OR] RewriteCond %{REMOTE_ADDR} ^789\.123\.456\. [OR] RewriteRule ^(.*)$ - [F,L] </IfModule> # alt block IP method <Limit GET POST PUT> order allow,deny allow from all deny from 123. deny from 123.456. deny from 123.456.789.0 </Limit>
Source: http://perishablepress.com/eight-way...s-mod_rewrite/
I've already seen that page along with many others like it since I did Google this problem before opening the thread. Those examples would apply to the entire website. I only need to restrict a specific IP from a specific file. That IP should be allowed to view any other files on the site except the one they're restricted from (submit.php). The idea is to keep spammer IP ranges off of my submit page, but allow legitimate users in those ranges to see everything else.

UPDATE: I fixed it by adding one line to your second example:

Code:
RewriteCond %{REQUEST_URI} submit.php [NC]
Code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} submit.php [NC] RewriteCond %{REMOTE_ADDR} ^111\.222\. [OR] RewriteCond %{REMOTE_ADDR} ^111\.223\. [OR] RewriteCond %{REMOTE_ADDR} ^111\.224\.150\. [OR] RewriteRule ^(.*)$ - [F,L] </IfModule>
Now I have a new question. How do I change this line...

Code:
RewriteRule ^(.*)$ - [F,L]
..to redirect to the home page instead of showing a 403 code?

Another update: I spoke to soon. Adding the line with REQUEST_URI is blocking all access to submit.php.

Last edited by vectro; 12-15-2012 at 12:40 PM.
 
Reply With Quote
  #8 (permalink)  
Old 12-15-2012, 01:13 PM
Super Moderator
Latest Blog:
None

 
Join Date: 11-11-11
Location: Copenhagen, Denmark
Posts: 3,003
iTrader: 1 / 100%
Well i couldn't find the code searching, so though i am no .htaccess expert, i manage to put this together, and tested it, so it should work:
Code:
RewriteEngine on RewriteCond %{Remote_Addr} ^198\.65\.168\.17$ RewriteCond %{REQUEST_URI} ^/tt.tt RewriteRule ^(.*) http://localhost/ [R,L]
If the user have the ip-adress 198.65.168.17 and is trying to read a page starting with /tt.tt then the user will be redirected to http://localhost/
 
Reply With Quote
  #9 (permalink)  
Old 12-17-2012, 09:06 AM
joshmac's Avatar
Junior Member
 
Join Date: 04-09-09
Location: Boston, MA
Posts: 27
iTrader: 0 / 0%
Quote:
Originally Posted by vectro View Post
I'm trying to use this code and it's not blocking the IP addresses. It's still allowing IPs from the specified ranges:

PHP Code:
<files submit.php>
order allow,deny
deny from 1.2.3
.
deny from 1.2.
allow from all
</files
What am I doing wrong and how to I correct it?
Maybe you can use that code and move the file to a specific folder and in that folder add:

PHP Code:
<files>
order allow,deny
deny from 1.2.3
.
deny from 1.2.
allow from all
</files
 
Reply With Quote
  #10 (permalink)  
Old 12-26-2012, 07:55 PM
vectro's Avatar
Contributing Member
 
Join Date: 12-29-08
Location: U.S.A.
Posts: 435
iTrader: 0 / 0%
First, I wanted to correct myself. None of what I posted in #7 worked. I had spoke to soon there.

The problem seems to have been caused by a bad Apache build. I rebuilt Apache and now the code I posted in the first place works. I thought anyone who needs to do the same thing might want to know that.

All set now. Thanks for everyone's help!
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is htaccess file and use of it ? copcop1973 Coding Forum 6 10-09-2012 01:18 AM
.htaccess file piper01 SEO Forum 4 03-09-2011 07:57 PM
Why we use .htaccess file ? jennycarol25 SEO Forum 6 07-26-2010 01:40 AM
Conflict, What is the right htaccess rule, default homepage file with htaccess? basketmen Coding Forum 2 01-20-2009 07:50 AM
Need help with HTACCESS file brandnew Coding Forum 2 12-02-2007 10:13 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 10:39 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2014 Escalate Media




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.