Typecho settings can be accessed by multiple domain names

Original link: https://rawchen.com/1575

reason

I want to open a new domain name qq.ht for the website. I thought that I only need to add a domain name to the original site of rawchen.com of the pagoda, but this method does not work, because the https access of a domain name requires a unique ssl certificate, so You can only create a new site and configure ssl separately. The root directory of the new site is still the original site. That is, just public services and resources. The problem is that the new site is configured and the domain name is resolved. However, when accessing the website, the static resource report cross-domain problem cannot be used. The error is as follows:

Access to font at ‘ https://rawchen.com/…../fontawesome-webfont.woff2?v=4.7.0 ‘ from origin ‘ https://qq.ht ‘ has been blocked by CORS policy: No ‘Access -Control-Allow-Origin’ header is present on the requested resource.

Solution

When viewing ./var/Widget/Options.php file, there is code to initialize site information.

 /** 动态获取根目录*/ $this->rootUrl = defined('__TYPECHO_ROOT_URL__') ? __TYPECHO_ROOT_URL__ : $this->request->getRequestRoot(); if (defined('__TYPECHO_ADMIN__')) { /** 识别在admin目录中的情况*/ $adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/'); $this->rootUrl = substr($this->rootUrl, 0, - strlen($adminDir)); } /** 初始化站点信息*/ if (defined('__TYPECHO_SITE_URL__')) { $this->siteUrl = __TYPECHO_SITE_URL__; } else if (defined('__TYPECHO_DYNAMIC_SITE_URL__') && __TYPECHO_DYNAMIC_SITE_URL__) { $this->siteUrl = $this->rootUrl; }

What does it mean, that is, Typecho has customized a global parameter __TYPECHO_DYNAMIC_SITE_URL__ , which is not enabled by default. If you configure it to enable, it will replace the access domain name under all access paths of the site with the domain name you requested. So if I configure this parameter to be enabled, I can access qq.ht without cross-domain, and all link prefixes are qq.ht, which is not constrained by the站点地址in the background. In this way, you can have a good experience with multi-domain access.

After understanding the principle, you only need to add two lines of configuration code in a new line under the background path in the config.inc.php file in the root directory of the website:

 /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 开启动态域名(跨域补救) */ define('__TYPECHO_DYNAMIC_SITE_URL__', true);

This article is reproduced from: https://rawchen.com/1575
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment