0

Hello I have a problem with header('Location: http://www.example2.com/'); while there is a query string.

Ok I will make the question easy to understand:

now I have a domain name http://example1.com/?url=url I want when someone want to access example1.com it redirects him to example2.com but if he types example1.com/?url=url nothing will happen so how can I do that please and thanks in advance

1
  • Something like if (count($_GET) > 0) { ... } if you want to check if the request has any parameters. Commented Apr 13, 2014 at 12:12

2 Answers 2

1

What do you use for redirecting? From your post's first line I assume, that you're redirecting the user via the PHP header function. So, check in PHP whether there is a query string or not:

<?php
if (empty($_SERVER["QUERY_STRING"]))
{
    header("Location:  http://www.example2.com/");
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

I assume you have index.php in root directory of domain example1.com. And you can use this;

<?php

if (empty($_GET["url"])) {
    header("Location:  http://www.example2.com/");
}

1 Comment

thankssss aloooooooottt I love you I forgot about this code :p

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.