一个页面的两个XML站点地图在.htaccess中重写

时间:2016-04-22 06:08:02

标签: php xml apache .htaccess mod-rewrite

我为同一页面创建了两个站点地图文件:

  • sitemap_en.xml
  • sitemap_sk.xml

同一页面正在处理两个域。

  • domain1 - 用于sk语言
  • domain2 - for en language

我需要在.htaccess中创建以下重写规则:

  • 如果domain1.sk/sitemap.xml返回sitemap_sk.xml
  • 如果domain2.com/sitemap.xml返回sitemap_en.xml

1 个答案:

答案 0 :(得分:2)

您可以在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]
  • 如果主机值为 www.domain1.sk /sitemap.xml 重写为 /sitemap_sk.xml >或 domain1.sk

  • 如果主机值 www.domain.com #2规则会将 /sitemap.xml 重写为 /sitemap_en.xml domain.com