0

HI i need to redirect url (http://www.mysite.com/?1 upto any numbers ?2, ?3 etc) to other url http://www.othersite.com

Mean www.mysite.com/?2 to www.othersite.com on not access like this page www.mysite.com/?1 any php code i need reply back

3 Answers 3

1

It seems from your question you're ignoring the ?n so it's simply:

index.php:

<?php

header("Location: http://www.othersite.com");

?>
Sign up to request clarification or add additional context in comments.

Comments

1

try

if (count($_GET))
    {
    header('Location:http://www.myothersite');
    }

1 Comment

Not work ... to Block this urls on random numbers mysite.com/?1 upto random or to 100
0

You could do the following:

<?php

if(isset($_GET['1'])) {
  header('location: http://othersite.com');
} elseif(isset($_GET['2']) {
  header('location: http://othersite.com/otherpage');
}
//and so on

Later edit:

<?php

    foreach($_GET as $key => $value) {
        if(is_int($key)) {
            header('location: http://othersite.com');
            exit;
        }
    }

4 Comments

Don't forget to add a die() statement after your header(); statements. I'm sure you know this, probably just answering the user's question directly, without the die() statement the rest of the page will continue to execute even though you are redirected.
the number are random so any other way?
Here you go, where the key is a random number. Check the "later edit"
get also this error (Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.