A
A
amazinginternetsites2015-12-23 11:37:03
PHP
amazinginternetsites, 2015-12-23 11:37:03

How to defeat a circular redirect?

Good afternoon.
When adding a site to Yandex.Webmaster, it returns the response "The site is performing a circular redirect."
Yandex answer:

When Yandex robots access the main page of your site, the server responds with a 302 redirect code to the same page, i.e. a circular redirect is obtained, for this reason the rights cannot be confirmed. I recommend that you check your server settings.
You need to configure the server in such a way that it responds to our robots with the code 200. Then the rights to the site in Yandex.Webmaster should be confirmed successfully.
If you have any difficulties with setting up the server, please contact your hosting provider's support service.

Host response:
Hello!
There are no settings that redirect the site from the server side. To resolve the situation, we recommend that you contact the developer of your site.

Through trial and error, I found a problem in this piece of code
if(!$city_id) $city_id = 4400;
      }
      
      setcookie('fields_city_id', $city_id, time()+86400, '/', null, false, false);
      
      $controller->redirect('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
      
    }

What's wrong here?
And how to overcome?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
W
wol_fi, 2015-12-23
@amazinginternetsites

What's wrong here?

By the way, the redirect occurs if the client does not have the fields_city_id cookie, but the problem is that the bot does not accept cookies, which is why the page is endlessly redirected to itself.
remove dependence on cookies, why redirect at all, for the sake of setting one cookie? Wouldn't it be easier to remove the redirect and just paste it after
setcookie('fields_city_id', $city_id, time()+86400, '/', null, false, false);

line
, and then the redirect is not needed, and the cookie is set, and it immediately lies in the global array.

L
LittleFatNinja, 2015-12-23
@LittleFatNinja

Do you know what a redirect is?
so the site redirects endlessly

G
GreatRash, 2015-12-23
@GreatRash

This is when you redirect to some page, and that page redirects back to you.

I
Igor Pushkarsky, 2015-12-23
@RainMEN

Check the settings in particular of the CMS itself, if it is on the CMS, if not, check where you have the main site mirror for example from www, and in your .htaccess settings it is indicated not to use www and redirect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question