?
Solved

.htaccess question (redirection)

Posted on 2006-11-05
5
Medium Priority
?
242 Views
Last Modified: 2010-04-22
Hi,

How would I redirect a user to a certain page based on their IP address (specifically an IP address block?)?

I.e., say I had "127.0." that I wanted to redirect to "access_denied.php" if they tried to access any page?

Thanks!
0
Comment
Question by:cool12399
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 400 total points
ID: 17879394
in .htaccess
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^127\.0\.
RewriteRule .* /error/access_denied.php [L,R] //L==don't try next rules, R==redirect(send 301 error code)

But If You would like just block some clients, refer http://httpd.apache.org/docs/2.0/mod/mod_access.html
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879398
One more thing, If You want block more that one pattern
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^127\.0\. [OR]
RewriteCond %{REMOTE_ADDR} ^192\.168\. [OR]
RewriteCond %{REMOTE_ADDR} ^10\.
RewriteRule .* /error/access_denied.php [L,R] //L==don't try next rules, R==redirect(send 301 error code)
0
 
LVL 10

Author Comment

by:cool12399
ID: 17895289
thanks! :) going to ask a new question shortly! :)
0
 
LVL 10

Author Comment

by:cool12399
ID: 17902910
hi, if you are still here -- just noticed a quick problem --

I get a 'cascading' error, i.e., if I put that in a root directory, and it 'redirects' to a subdirectory, I get the message that it is looping/trying
to redirect infinitely...

what .htaccess file would I need to put in say the /error/ directory to prevent that?

thanks!
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17904541
Usually it's solved this way
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^127\.0\.
RewrtieCond %{REQUEST_URI} !^/error/access_denied.php
RewriteRule .* /error/access_denied.php
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (https://kb.isc.org/article/AA-01272), affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question