Chloe Chloe - 6 months ago 15
PHP Question

Adding Fastly CDN causes redirects to wrong host in Yii. AKA: Why is my Yii app with custom domain redirecting to app.herokuapp.com?

I added Fastly CDN to my site, and now when I try to log into the admin section, it will redirect to site.herokuapp.com/site/login instead of www.site.com/site/login. I suppose this is because Fastly is requesting the page on the backend with

HOST: site.herokuapp.com
. Is there a setting in Yii to change the host name in production so it redirects to the correct domain? I tried searching the docs for 'domain' or 'host' but could not find any relevant settings. These were the closest docs I could find.

http://www.yiiframework.com/doc-2.0/guide-security-authorization.html

http://www.yiiframework.com/doc-2.0/yii-web-user.html#loginRequired()-detail

http://www.yiiframework.com/doc-2.0/yii-web-user.html#$loginUrl-detail

Answer

You have to change the default host, general.default_host, so it uses that when requesting from the back end.

$ curl -X PUT -H $FASTLY_API_KEY "$FASTLY_API_URL/version/3/clone"
# note the new version number
$ curl -X PUT -d "general.default_host=www.site.com" -H $FASTLY_API_KEY "$FASTLY_API_URL/version/5/settings"
$ curl -X PUT -H $FASTLY_API_KEY "$FASTLY_API_URL/version/5/activate"
Comments