Solved

.htaccess question (redirection)

Posted on 2006-11-05
5
240 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 100 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

​Being a Managed Services Provider (MSP) has presented you  with challenges in the past— and by meeting those challenges you’ve reaped the rewards of success.  In 2014, challenges and rewards remain; but as the Internet and business environment evol…
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 …

749 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