Search code examples
.htaccessmod-rewritehttp-proxy

send all .xml requests to proxy


I have an Angular application that pulls in content from a CMS for articles via an API. I want to utilize the XML sitemap generated by the CMS. The CMS is hosted at content.example.com and the Angular site is the www. What I would like to do is catch all .xml requests and load the content site by proxy. What I have in my .htaccess is:

RewriteCond %{REQUEST_FILENAME}
RewriteRule ^\.*?\.xml$ https://content.example.com/$2 [P,L]

However, that is not working. Fairly new to mod rewrite so I am assuming my logic is off. Not finding a lot of examples of this. Any help would be appreciated.


Solution

  • You could write your rule this way

    # Only apply next rule when domain is www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    # (Proxy) rewrite all xml files to its proxy equivalent
    RewriteRule ^(.+)\.xml$ https://content.example.com/$1.xml [P]