Jump to content

.htaccess redirect an IP


kYd

Recommended Posts

I'm certainly no .htaccess guru, but I don't think it is capable of redirecting users based on their IP, although it can block users based on IP. I believe you may have to whip up a small php/cgi/etc script to do it.

EDIT: Well I guess you could just block them and use custom error pages...

Link to comment
Share on other sites

If the server you are using has PHP installed you can use the following codeto do URL redirects:

<?php

Header("Location: <URL gose here>");

?>

This will work even if the user has JavaScript disabled on they'er browser as it is part of the HTML 4.01 standered.

Link to comment
Share on other sites

What do you mean with an IP address? You could do some thing like this for example:

<?php

Header("Location: http://207.46.198.30/");

?>

With that code when ever some one visited the page you put that code on (even if they have JavaScript disabled as I have alredy explained) they will be redirected to Microsofts website.

Link to comment
Share on other sites

Cheers Sparda, how would I go about using that with an IP address.

If that don't work I guess Dr Zaius method should work.

Thanks

Like Dr Zaius said, there is no way to redirect a certain IP with .htaccess, but what he suggested would work. And heres a solution in PHP to send certain IP addresses to a page. You can put this at the very top of any of your pages, say your index.php (if your host supports php of course) and if someone has the IP you specified they'll be redirected to the other page, but everyone else will see the normal page.

<?php



$address = $HTTP_SERVER_VARS["REMOTE_ADDR"]; 



if ($address == "xxx.xxx.xxx.xxx") {

    header("Location: goatse.html");

}





?>

Link to comment
Share on other sites

Cheers Sparda, how would I go about using that with an IP address.

If that don't work I guess Dr Zaius method should work.

Thanks

Like Dr Zaius said, there is no way to redirect a certain IP with .htaccess, but what he suggested would work. And heres a solution in PHP to send certain IP addresses to a page. You can put this at the very top of any of your pages, say your index.php (if your host supports php of course) and if someone has the IP you specified they'll be redirected to the other page, but everyone else will see the normal page.

<?php



$address = $HTTP_SERVER_VARS["REMOTE_ADDR"]; 



if ($address == "xxx.xxx.xxx.xxx") {

    header("Location: goatse.html");

}





?>

Thanks that worked!

Let the evil rampage begin :twisted:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...