Skip to main content
All CollectionsWordPress Plugin
How to crawl a WordPress site that internally uses a different domain from the public URL
How to crawl a WordPress site that internally uses a different domain from the public URL

Find out how to troubleshoot WordPress Plugin issue when WordPress site uses different URLs

Lucy avatar
Written by Lucy
Updated over 4 months ago

When using the Ahrefs Wordpress plugin, there can be a case where after running the content audit, you see incomplete or empty results.

This is likely due to your WordPress website using 2 different URLs: one internal / staging URL, and one public facing URL. For the plugin to work, you might need to apply more advanced settings:


​Let's imagine the staging website URL is blog.ahrefs.com and the public URL is ahrefs.com/blog/.

To make sure the plugin picks up the correct pages in your Wordpress website, please add the following block of code to your functions.php file (https://developer.wordpress.org/themes/basics/theme-functions/#what-is-functions-php) or to your active theme.

You will need to specify the domain name of public URL (in our example it is 'ahrefs.com') and the public URL of the site (in our example it is 'https://ahrefs.com/blog'). Remember to replace both these fields with your own domain name and the public URL:

// Ahrefs domain redirect begin.
define('REPLACEMENT_DOMAIN', 'ahrefs.com'); // public domain name.
define('REPLACEMENT_SITE_PATH', 'https://ahrefs.com/blog'); // public URL of site, without trailing slash.
add_filter( 'ahrefs_seo_post_url', function( $domain ) {
return rtrim( str_replace( home_url(), REPLACEMENT_SITE_PATH, $domain ), '/');
});
add_filter( 'ahrefs_seo_domain', function( $domain ) {
return REPLACEMENT_DOMAIN;
});
add_filter( 'ahrefs_seo_search_traffic_url', function( $domain ) {
return rtrim( str_replace( home_url(), REPLACEMENT_SITE_PATH, $domain ), '/');
} );
// Ahrefs domain redirect end.

Did this answer your question?