Background
Illustrating with a concrete example is the best way to demonstrate why this is a bad idea, especially if you want your site to be portable (e.g., migrating from multisite to single site, or vice versa).
Case development example
Say, for example, you have a URL to your image like this on your subsite:
https://yoursite.test/my-subsite/wp-content/themes/test-theme/test.jpgFor which:
https://yoursite.test/ -> This is your main site URL (your multisite uses a subdirectory format). And then:
https://yoursite.test/my-subsite/ is your subsite URL.
Supposing you use the relative URL version of this image in your WordPress site like this:
/my-subsite/wp-content/themes/test-theme/test.jpg
While you are still in multisite, the relative URL should still work because when WordPress sees:
/my-subsite/wp-content/themes/test-theme/test.jpg
It will resolve correctly and append your main site to it so that it will become:
https://yoursite.test/my-subsite/wp-content/themes/test-theme/test.jpg
Why do relative URLs cause migration problems?
Now, suppose you decide to migrate this subsite to a standalone WordPress installation (single-site) using Prime Mover. Say, for example, your new domain in a single-site is:
https://my-standalonesite.test/
The search-and-replace process during migration automatically detects all URLs and paths and replaces them with the target site paths/URLs.
However, if you are using a relative URL, this won’t work. Looking into this relative URL path:
/my-subsite/wp-content/themes/test-theme/test.jpg
Prime Mover’s automated search-and-replace process has no idea how to handle this URL. It is because it has no domain attached. Therefore, the above URL is skipped during search-and-replace processing. It remains as a relative URL.
As a result, the above relative URL at the target standalone site becomes:
https://my-standalonesite.test/my-subsite/wp-content/themes/test-theme/test.jpg
Obviously, this does not exist on your target site, which is why it returns a 404 error for the image.
Fix the issue: Always use absolute URLs!
Instead of using relative URLs, use absolute URLs. These URLs show the full URL, including the domain name, path, and query parameters. This makes your site fully portable for migrations. Since the domain name is included, it will be searchable and replaceable during the Prime Mover migration process.
Let’s use the above example – supposing you use absolute URLs instead of relative URLs to render your image. The URL that is stored inside your database for that example image is:
https://yoursite.test/my-subsite/wp-content/themes/test-theme/test.jpg
When this is migrated to a WordPress single site with a domain name:
https://my-standalonesite.test/
The subsite URL:
https://yoursite.test/my-subsite/
This will be searched and replaced with the single-site domain name: https://my-standalonesite.test/
Therefore, it will become:
https://my-standalonesite.test/wp-content/themes/test-theme/test.jpg
The image URL will now be correct after migration. This is why you should always use absolute URLs rather than relative ones.
Summary
- Relative URLs are not friendly for migration.
- Absolute URLs are the best all-around solution to generating URLs in your site. This makes your site portable and migration-friendly.