Rewriting .htaccess rules for sitemaps in multisite with domain mapping

I’ve been having issues with Smartcrawl and the sitemaps of the different sites. Apparently, there was a CORS issue, which is now resolved. So, I can find the sitemaps in /wp-content/uploads/sites/2/sitemap.xml and they work. 

The only problem left is that I need to use htaccess to create the appropriate rewrite rules.

  • Ash
    • Code Norris

    Hello Jasper

    Looks like you are on NGINX server. If so, then htaccess won’t work for that. You have to write NGINX rule to rewrite.

    You can try the following rule for this rewrite:

    location / {
    if ($http_host ~* "^kwaliteitsstukadoor.nl"){
    rewrite ^/sitemap.xml$ /wp-content/uploads/sites/sitemap.xml?&$query_string;
    }
    }

    You can also use this site to convert htaccess rule to nginx rule: https://winginx.com/en/htaccess

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,

    Ash

  • Jasper BO
    • Flash Drive

    Hi Ash,

    That’s what we tried first, but we use NGINX in reverse-proxy, so I’ve been told by my server administrator. Which apparently means we should use htaccess.

    And if I try to add your code to the httpd.conf file via DirectAdmin I get the following error:

    AH00526: Syntax error on line 22 of /usr/local/directadmin/data/users/bouwonline/httpd.conf:

    Invalid command ‘location’, perhaps misspelled or defined by a module not included in the server configuration

    Thanks, Jasper

  • Ash
    • Code Norris

    Hello Jasper

    I am not familiar with reverse-proxy technique though. If you think the htaccess would work, then the rule should be:

    RewriteCond %{HTTP_HOST} ^kwaliteitsstukadoor.nl [NC]
    RewriteRule ^sitemap.xml$ /wp-content/uploads/sites/2/sitemap.xml

    However, about the error above, did you put the location within server block? Is it possible to paste the full file content in http://pastebin.com and send us the link? Then we could check.

    Have a nice day!

    Cheers,

    Ash

  • Jasper BO
    • Flash Drive

    Never mind, fixed it. This is the right code:

    RewriteCond %{HTTP_HOST} ^www.kwaliteitsstukadoor.nl$
    RewriteRule ^sitemap.xml /wp-content/uploads/sites/2/sitemap.xml

    So without the $ after sitemap.xml and without any commands in brackets after each line, as everything is located on the same server.