steelbull steelbull - 7 months ago 35
PHP Question

Two XML sitemaps for one page rewrited in .htaccess

I have created two sitemap files for the same page:


  • sitemap_en.xml

  • sitemap_sk.xml



Same page is working on two domains.


  • domain1 - for sk language

  • domain2 - for en language



I need to create following rewrite rule in .htaccess:


  • If domain1.sk/sitemap.xml Return sitemap_sk.xml

  • If domain2.com/sitemap.xml Return sitemap_en.xml


Answer

You can use the following conditional rules in htaccess :

RewriteEngine on

##1)if host=="www.domain1.sk##
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.sk$
##rewrite "/sitemap.xml" to "/sitemap_sk.xml"##
RewriteRule ^/?sitemap\.xml$ /sitemap_sk.xml [NC,L]
##2)if host=="www.domain2.com##
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$
##rewrite "/sitemap.xml" to "/sitemap_en.xml"##
RewriteRule ^/?sitemap\.xml$ /sitemap_en.xml [NC,L]
  • The first rule will rewrite /sitemap.xml to /sitemap_sk.xml if the host value is www.domain1.sk or domain1.sk .

  • The #2 rule will rewrite /sitemap.xml to /sitemap_en.xml if the host value is www.domain.com or domain.com .

Comments