Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 使用htaccess将子域文件重写到文件夹中_.htaccess_File_Subdomain_Rewrite_Directory - Fatal编程技术网

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

.htaccess 使用htaccess将子域文件重写到文件夹中,.htaccess,file,subdomain,rewrite,directory,.htaccess,File,Subdomain,Rewrite,Directory,我需要将子域上的文件重写为存储在具有子域名称的文件夹中的文件。仅应重写以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/site

我需要将子域上的文件重写为存储在具有子域名称的文件夹中的文件。仅应重写以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
因此,子域名用作“重写到”路径中的文件夹。这应该是重写而不是重定向。此外,最好有一些规则可以用于任何域,而无需每次更改域名。

您可以将子域与条件匹配,然后用规则重写它:

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/content/sitemaps/%1/$1 [L]
也许您想在.xml上添加一个过滤器

加:

RewriteCond %{REQUEST_FILENAME} \.xml
编辑

对于以站点地图开头的文件:


这将匹配以sitemap结尾的任何字符串。和结束。=>这是一个与目录不匹配的文件名。

这没有考虑到要重写的文件必须以sitemap开头。扩展可以不同于XML。不,它不起作用。按照您的建议使用RewriteRule,服务器会生成500个未找到.domain.com的内部错误。如果我只留下一条路http://domain.com 部分,什么都没发生,它不起作用。我认为,为了使重写工作正常,它不能包括域,重写应该指向同一个域,或者在这种情况下指向子域。我将看到这一点。让我想想。但你们可以改变域名,这是肯定的。也许吧,但无论如何都不行。关键是让它保持在同一个域上以获取文件,不需要跨域或主域。您有/var/log/apache2中的日志吗?您还可以使用RewriteLog/var/log/apache2/rewrite.log和RewriteLogLevel 3或4激活mod_rewrite日志。
RewriteCond %{REQUEST_FILENAME} sitemap.*\..+$