使用htaccess的重写子站点文件的文件夹 [英] Use htaccess to rewrite subdomain files to a folder

查看:197
本文介绍了使用htaccess的重写子站点文件的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重写的子域一个文件夹中存储的与子域的名称的文件。只有以网​​站地图文件应该改写。因此,如果要求是这样的:

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

这些应该重写文件:

/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.

推荐答案

您可以匹配的子站点的条件,然后用该规则重写一遍:

You can match the subdomain with a condition, then rewrite it with the rule :

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/content/sitemaps/%1/$1 [L]

也许你想添加一个过滤器的.xml

Maybe you want to add a filter on .xml

地址:

RewriteCond %{REQUEST_FILENAME} \.xml

修改

对于 sitemap文件开始

RewriteCond %{REQUEST_FILENAME} sitemap.*\..+$

这将匹配与网站地图完成任何字符串。和结束。 =>这是一个文件名不是目录内的比赛。

This will match any string that finish with sitemap. and end. => this is a filename not an inner match of directory.

这篇关于使用htaccess的重写子站点文件的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆