Kalti
Kalti

Reputation: 501

.htaccess XML-Sitemap Redirect for multi-domain

My homepage is accessible via 2 different domains.

1: https://example.at

2: https://example.de

I manually created for each site the sitemap.xml which is located in the root directory of my page. (sitemap1.xml / sitemap2.xml)

After entering the URL example.at/sitemap.xml or example.de/sitemap.xml I need a redirect to the correct .xml file.

1: https://example.at/sitemap.xml => https://example.at/sitemap1.xml

2: https://example.de/sitemap.xml => https://example.de/sitemap2.xml

I tried the follwing redirect-rule:

RewriteCond %{REQUEST_URI} ^\/sitemap\.xml$
RewriteRule .* https://example.at/sitemap1.xml [R=301,L]

RewriteCond %{REQUEST_URI} ^\/sitemap\.xml$
RewriteRule .* https://example.de/sitemap2.xml [R=301,L]

No matter if I enter the .de or the .at address I will be forwarded to: https://example.at/sitemap1.xml.

I have no experience with rewrite-rules so I used: https://www.webcellent.com/tools/modrewrite/

Would appreciate any help.

Thanks in advance!

Upvotes: 0

Views: 829

Answers (1)

Kalti
Kalti

Reputation: 501

RewriteCond %{HTTP_HOST} ^example.at$
RewriteCond %{REQUEST_URI} /sitemap.xml
RewriteRule ^(.*)$ https://example.at/sitemap1.xml [R=301,L]

RewriteCond %{HTTP_HOST} ^example.de$
RewriteCond %{REQUEST_URI} /sitemap.xml
RewriteRule ^(.*)$ https://example.de/sitemap2.xml [R=301,L]

Edit: Might have been a caching issue

Upvotes: 0

Related Questions