skip to Main Content

So I have a WordPress site hosted on wpengine with Yoast SEO. So all the links in the site map are like https://example-site.wpenginepowred.com.

We also use AWS cloud front to direct traffic to either the WordPress site or web app server so we can set up access to the sitemaps via cloud front to be accessible on www.example.com/sitemap for example but all the urls are still in the previous wpengine powered format

Tried to add a find and replace to functions.php like the below

add_filter('wpseo_xml_sitemap_post_url', 'replace_domain_in_sitemap', 10, 2);
 
 function replace_domain_in_sitemap($url, $post) {
     return str_replace('example-site.wpenginepowered.com/', '/www.example.com/', $url);
 }

Notice the extra / before example.com. if I remove all the url content comes back as blank and with the extra it builds ok with https:///www.example.com.

Any ideas why the sitemap doesn’t like it without the extra /?? Just seems super weird that it does this?

2

Answers


  1. For this I suggest you to do Search & Replace these URLs with the help Search & Replace plugin, once you install this plugin you can go to Tools > Search & Replace and here you can replace URl as per your need.

    enter image description here

    Login or Signup to reply.
  2. your issue is with the extra slash. When replacing . don’t add slashes manually.just swap the domain without extra slashes like this:

    add_filter('wpseo_xml_sitemap_post_url', 'replace_domain_in_sitemap', 10, 2);
    
    function replace_domain_in_sitemap($url, $post) {
        return str_replace('example-site.wpenginepowered.com', 'www.example.com', $url);
    }
    

    this shuold fix it . Just replace the domain, and let WordPress handle the rest.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search