Solved

.htaccess question (redirection)

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

​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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now