Puo's 菜园子 学习园地 http://puo.cn
易记网址: http://wordpress.cn.com

WordPress 设置多域名可访问

e="box-sizing: border-box; margin: 10px 0px !important; white-space: normal; word-break: break-all; line-height: 2; color: #343a40; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">如果你使用过 wordpress,并更换过域名,那么你可能经历过循环重定向进不去 wordpress 的情况,原因就是数据库的 wp-options 表的 siteurl 和 home 选项还依然是旧的域名。

如果只能设置数据库来指定域名,这样的话就不能设置多域名了,这里分享一个多域名的访问的方式,并且静态资源都将通过不带域名的根路径访问。

只需要修改网站根目录的 wp_config.php 的文件,以下内容在:require_once ABSPATH . 'wp-settings.php'; 前面设置。

<div class="pk-code-tools" style="box-sizing: border-box; white-space: normal; word-break: break-all; background-color: #0b1c2c; border-top-left-radius: var(--pk-g-box-radius); border-top-right-radius: var(--pk-g-box-radius); padding: 5px 10px 0px; display: flex; place-content: center space-between; color: #343a40; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pre-id="hljs-item-0">
<td class="hljs-ln-line hljs-ln-numbers" style="box-sizing: border-box; word-break: normal !important; user-select: none; text-align: center; color: #8e8d8d; vertical-align: top; display: inline-block; margin-right: 10px; padding: 0px; border: 0px solid inherit;" data-line-number="1">
# 方式一、 确定全部为 https
define(‘WP_SITEURL’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);
define(‘WP_HOME’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);
# 方式二、防止恶意解析
$pattern = ‘/^[a-z0-9]+\.amjun\.com$/’;
$domain = array(“www.amjun.com”, “amjun.com”);
if (in_array($_SERVER[‘HTTP_HOST’], $domain) || preg_match($pattern, $_SERVER[‘HTTP_HOST’])) {
define(‘WP_SITEURL’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);
define(‘WP_HOME’, ‘https://’ . $_SERVER[‘HTTP_HOST’]);
}

注意:没有如下设置可能进不去后台。(猜测后台默认不开启ssl访问,所以访问到 http 链接,然后一直跳转)

# 强制后台和登陆使用 ssl,这样后台发起的请求全部都是 https
$_SERVER[‘HTTPS’] = ‘on’;
define(‘FORCE_SSL_LOGIN’, true);
define(‘FORCE_SSL_ADMIN’, true);

静态资源也设置为根路径,这样的话可以媒体链接都将不带域名。

define('WP_CONTENT_URL', '/wp-content');

e="box-sizing: border-box; margin: 10px 0px !important; white-space: normal; word-break: break-all; line-height: 2; color: #343a40; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">64ca76e37e043

提醒:本文发布于402天前,文中所关联的信息可能已发生改变,请知悉!

打赏
谢谢谅解上文的粗糙,允许转载,请注明转载地址:Puo's 菜园子 » WordPress 设置多域名可访问
分享到

评论 抢沙发

做一个好的个人学习园地

主要网建,域名、集装箱物流、生活方法论的学习及研究,整理等内容

我的原创博客-忆秋年Puo's菜园子-我的学习园地

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册