使用htaccess将子域文件重写到文件夹中

|| 我需要将子域上的文件重写为具有子域名称的文件夹中存储的文件。仅应重写以“ 0”开头的文件。因此,如果请求如下所示: http://demo.domain.com/sitemap.xml http://demo.domain.com/sitemap_more.xml http://test.domain.com/sitemap.xml http://test.domain.com/sitemap_alpha.xml 这些应该重写为文件: /content/sitemaps/demo/sitemap.xml /content/sitemaps/demo/sitemap_more.xml /content/sitemaps/test/sitemap.xml /content/sitemaps/test/sitemap_alpha.xml 因此,子域名用作重写路径中的文件夹。这应该重写而不是重定向。同样,最好有一个规则可以与任何域一起使用而无需每次都更改域名。     
已邀请:
您可以将子域与条件匹配,然后使用以下规则将其重写:
RewriteCond %{HTTP_HOST} ^([^.]+)\\.domain\\.com
RewriteRule ^(.*)$ http://domain.com/content/sitemaps/%1/$1 [L]
也许您想在.xml上添加过滤器 添加:
RewriteCond %{REQUEST_FILENAME} \\.xml
编辑 对于以
sitemap
开头的文件:
RewriteCond %{REQUEST_FILENAME} sitemap.*\\..+$
这将匹配以Sitemap结尾的任何字符串。并结束。 =>这是文件名,而不是目录的内部匹配项。     

要回复问题请先登录注册