MacMac
MacMac

Reputation: 35321

Redirect on deny | htaccess

How can I get the user to be redirected if their IP was matched on the deny of an IP address, e.g.

<Limit GET POST PUT>
  order allow,deny
  allow from all
  deny from {removed IP address}
</Limit>

I need them to be redirected to a specific website when they are denied from accessing.

Needing help with this..

Upvotes: 7

Views: 25407

Answers (3)

Adhitya Ganesan
Adhitya Ganesan

Reputation: 27

Make sure to comment out the directives in welcome.conf, otherwise it will keep overriding your custom ErrorDocument directive.

After that, you can put your ErrorDocument directive in VirtualHost, Document directive or in your .htaccess https://httpd.apache.org/docs/2.4/custom-error.html

Like so:

ErrorDocument 403 <Local file/Remote URL>

And if this doesn't work, then you will have to look into your CORS rule

Upvotes: 0

C&#233;sar Ara&#250;jo
C&#233;sar Ara&#250;jo

Reputation: 152

Simple solution using only htaccess

ErrorDocument 403 https:///google.com
Order Allow,Deny
Allow from 127.0.0.0/8
Allow from x.x.x.x
Allow from y.y.y.y

Upvotes: 3

bradym
bradym

Reputation: 4961

Setup a script to handle 403 errors by adding this line to your .htaccess:

ErrorDocument 403 /forbidden.php

Then handle the redirect in the script:

<?php
header('Location: http://google.com');

Or to keep it all in .htaccess you could do:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} 127.0.0.1
RewriteRule (.*) http://google.com [R]

Upvotes: 10

Related Questions