How to Lock WordPress to Your Domain in wp-config.php (Bitnami / AWS Fix)

On AWS Bitnami WordPress installs, WordPress is often configured to dynamically determine its site URL based on how the site is accessed (domain or server IP). While this can be convenient during setup, it can cause serious issues later — especially with page builders like Elementor — where images and assets suddenly start loading from the server IP instead of the domain.

This guide shows how to permanently lock WordPress to your domain using wp-config.php, preventing IP-based URLs from ever coming back.

By default, Bitnami includes logic in wp-config.php that sets WP_HOME and WP_SITEURL dynamically using $_SERVER['HTTP_HOST']. This means:

  • If the site is accessed via the domain, WordPress uses the domain
  • If the site is accessed via the server IP, WordPress becomes the IP
  • Page builders (like Elementor) may regenerate assets using the IP
  • Image URLs can suddenly revert to http://IP:80/...

Even if your database values are correct, this behavior can cause recurring problems.

You should lock the site URL in wp-config.php if:

  • You’re using AWS Bitnami WordPress
  • You ever accessed the site via its server IP
  • Images or assets load from an IP instead of your domain
  • You use Elementor or another builder that generates static files
  • You want to prevent future regressions entirely

This fix is safe for production and recommended once your domain is finalized.

Step 1: Edit wp-config.php

sudo nano /opt/bitnami/wordpress/wp-config.php

Step 2: Remove Bitnami’s Dynamic URL Logic

Find and remove this entire block if it exists:

/**
 * The WP_SITEURL and WP_HOME options are configured to access from any hostname or IP address.
 */
if ( defined( 'WP_CLI' ) ) {
    $_SERVER['HTTP_HOST'] = '127.0.0.1';
}

define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' );

This is the logic that allows WordPress to switch between domain and IP.

Step 3: Lock WordPress to Your Domain

Add the following once, near the bottom of the file, above the “stop editing” line:

define('WP_HOME', 'https://yourdomain.com');
define('WP_SITEURL', 'https://yourdomain.com');

define('FORCE_SSL_ADMIN', true);

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

Replace yourdomain.com with your actual domain.

This ensures WordPress:

  • Always identifies itself as the domain
  • Never switches to the server IP
  • Correctly handles HTTPS behind AWS / Bitnami proxies

Step 4: Save the File

CTRL + O + Enter + CTRL + X

Step 5 (Elementor Sites Only): Regenerate Assets

If your site uses Elementor and previously showed IP-based image URLs, run:

sudo rm -rf wp-content/uploads/elementor/css/*

Then in WordPress Admin:

  • Go to Elementor → Tools
  • Click Regenerate Files & Data

This forces Elementor to rebuild assets using the locked domain.

How to Verify the Fix (No phpMyAdmin Needed)

From the WordPress root directory:

sudo wp eval 'echo home_url() . PHP_EOL . site_url();'

You should see:

https://yourdomain.com
https://yourdomain.com

Then inspect an image in your browser and confirm it loads from your domain, not an IP.

Leave a Reply

Your email address will not be published. Required fields are marked *