Search code examples
.htaccesshttp-redirect

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..


Solution

  • 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]