Solved

.htaccess question (redirection)

Posted on 2006-11-05
5
239 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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Certified Pentester Exam - need assistance on compiling an exploit 6 395
LDAP server set up question 5 151
SSL question 7 96
CentOS 6.7 User Audit 3 96
​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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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