2024-09-08 19:51:03 分类:域名与建站
阅读() 评论(0)
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">
|
|
|
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 链接,然后一直跳转)
|
|
|
|
|
$_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;">
提醒:本文发布于402天前,文中所关联的信息可能已发生改变,请知悉!
白天晕乎乎,晚上睡不着的中年大叔
http://puo.cn
http://wordpress.cn.com