You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

地址栏显示localhost却加载线上WordPress站点,求排查方案

解决思路
  • 补全/etc/hosts的localhost映射
    当前你的hosts文件缺少127.0.0.1 localhost的映射,添加这一行:

    127.0.0.1       localhost
    127.0.1.1       dara-HP-Pavilion-Notebook-15-bc5xxx
    

    保存后刷新DNS缓存(Ubuntu/Debian可执行sudo systemctl restart systemd-resolved),确保localhost正确指向本地回环地址。

  • 确认wp-config-local.php被正确加载
    检查主wp-config.php文件末尾是否有引入wp-config-local.php的代码:

    if (file_exists(dirname(__FILE__) . '/wp-config-local.php')) {
        require_once(dirname(__FILE__) . '/wp-config-local.php');
    }
    

    若没有这段代码,wp-config-local.php里的配置不会生效,需手动添加。

  • 检查WordPress数据库中的站点地址配置
    即使wp-config里设置了WP_HOME和WP_SITEURL,数据库旧值仍可能干扰:

    1. 登录本地数据库,找到WordPress选项表(默认是wp_options)
    2. 将option_name为siteurl和home的option_value修改为http://localhost(若有自定义端口则加上,比如http://localhost:8080)
  • 清除浏览器HSTS缓存
    普通缓存清理无法清除HSTS强制跳转规则:

    • Chrome:地址栏输入chrome://net-internals/#hsts,在「Delete domain security policies」中输入线上域名,点击「Delete」
    • Firefox:输入about:config,搜索network.stricttransportsecurity.preloadlist,临时设置为false,重启浏览器后再改回true
  • 检查Apache虚拟主机配置
    确认Apache虚拟主机配置文件(通常在/etc/apache2/sites-available/)中,DocumentRoot指向本地代码仓库目录:

    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot /path/to/your/local/repo
        <Directory /path/to/your/local/repo>
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    

    确认该虚拟主机已启用(执行sudo a2ensite your-config.conf),并重启Apache。

  • 排查代码中的硬编码地址
    搜索本地代码仓库,查找是否有硬编码的线上站点地址:

    grep -r "https://your-online-domain.com" /path/to/your/local/repo
    

    重点检查主题functions.php、插件文件、静态资源引用等,替换为本地地址。

内容的提问来源于stack exchange,提问作者Myuser03

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 06:15:45