使用htaccess将子域文件重写到文件夹
我需要将子域上的文件重写为存储在具有子域名称的文件夹中的文件。仅应重写以 sitemap
开头的文件。因此,如果请求如下所示:
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
因此,子域名用作重写路径中的文件夹。这应该是重写而不是重定向。此外,最好有适用于任何域的规则,而无需每次都更改域名。
I need to rewrite a files on subdomain to files stored in the folder with name of the subdomain. Only files that start with sitemap
should be rewritten. So, if the requests look like this:
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
These should rewrite to files:
/content/sitemaps/demo/sitemap.xml /content/sitemaps/demo/sitemap_more.xml /content/sitemaps/test/sitemap.xml /content/sitemaps/test/sitemap_alpha.xml
So, subdomain name is used as a folder in the rewrite-to-path. This should be rewriting NOT redirecting. Also, it would be good to have rules that will work with any domain without need to change domain name everytime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将子域与条件匹配,然后使用规则重写它:
也许您想在 .xml 上添加过滤器
添加:
编辑
对于以
sitemap
开头的文件:这将匹配以站点地图结尾的任何字符串。并结束。 =>这是一个文件名,而不是目录的内部匹配。
You can match the subdomain with a condition, then rewrite it with the rule :
Maybe you want to add a filter on .xml
Add :
Edit
For file beginning with
sitemap
:This will match any string that finish with sitemap. and end. => this is a filename not an inner match of directory.