V
V
Vladimir2017-04-24 19:19:49
PHP
Vladimir, 2017-04-24 19:19:49

How to make a redirect if the get parameter is passed to the homepage?

How to make a redirect if we make such a request site.ru/?params=1 or site.ru/? and redirects just to site.ru
Thanks for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-04-24
@PavelFokeev

if(count($_GET) > 0 || substr($_SERVER['REQUEST_URI'], -1) == '?') header('Location: /');

First condition
count($_GET) > 0
will check if GET parameters were passed. But if the query is just
site.ru/?
, the condition will return 0. Therefore, the second condition is to check if there is a question mark at the end of the query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question