M
M
Maxim Timofeev2017-04-10 10:53:00
Yii
Maxim Timofeev, 2017-04-10 10:53:00

Why did the redirect suddenly become circular?

Once upon a time there was an ordinary .htaccess

.htaccess code
RewriteEngine on

RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

And he perfectly redirected from http and www to https without www. But the evil hosters nic.ru, without declaring war, changed something on the server. And it started giving error ERR_TOO_MANY_REDIRECTS
Any attempt to edit .htaccess results in the above error. I commented out the redirects and wrote a hell of a bike yii2 (php framework), but I don't like it:
bike code (yii2)
public function beforeAction($action)
    {
        if(!Yii::$app->request->getIsSecureConnection()){
            $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
            return $this->redirect($redirect,301);
        }
        return parent::beforeAction($action);
    }

If there are more elegant solutions - it will be very much appreciated.
There is no desire to understand and correspond with hosters (got it). I have vds (not nic.ru of course), as soon as I have time I will definitely move, but maybe someone has already come across it. This happened a couple of weeks ago, so maybe someone already wrote to them knows the recipe.
Share hellish torments of correspondence pliz.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-04-10
@shambler81

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^.*$ http://%{SERVER_NAME}%{REQUEST_URI}

Try this.
But it seems to me that they did the following
In the virtual host, they added a redirect of the main mirror.
Open it up and take a look. connect via ssh and look at the settings in apache. Edit will not give but read will give.
But there may already be a redirect, for example, to a mirror, and then there will really be a cycle.
Again, you cited several lines at once, that when you turn off any of them, the cycle is saved?
and what redirect specifically leads to a cycle?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question