[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

.htaccess question (redirection)

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
cool12399
Asked:
cool12399
  • 3
  • 2
1 Solution
 
ravenplCommented:
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
 
ravenplCommented:
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
 
cool12399Author Commented:
thanks! :) going to ask a new question shortly! :)
0
 
cool12399Author Commented:
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
 
ravenplCommented:
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now