Php 这些用于子域的htaccess重写规则有什么问题

Php 这些用于子域的htaccess重写规则有什么问题,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我们有两个子域用于并行加载: image.example.com other.example.com 我们不希望人们能够通过这两个域中的任何一个来浏览我们的网站,但我们确实希望使用它们来提供某些内容,如图像、js文件、css等 Not okay, redirect to www -> http://image.example.com Not okay, redirect to www -> http://image.example.com/sales.php Okay, do not

我们有两个子域用于并行加载:

image.example.com other.example.com

我们不希望人们能够通过这两个域中的任何一个来浏览我们的网站,但我们确实希望使用它们来提供某些内容,如图像、js文件、css等

Not okay, redirect to www -> http://image.example.com
Not okay, redirect to www -> http://image.example.com/sales.php
Okay, do not redirect     -> http://image.example.com/images/picture.jpg
Okay, do not redirect     -> http://image.example.com/images/picture.png
Okay, do not redirect     -> http://other.example.com/images/picture.gif
Okay, do not redirect     -> http://other.example.com/resources/styles.css
以下是我用来实现这一目标的规则,但它们似乎不起作用:

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteCond %{HTTP:X-HOST} !^image.example.com$ [NC]
RewriteCond %{HTTP:X-HOST} !^other.example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt
RewriteCond %{REQUEST_URI} !^/forums/(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html? [NC]
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^image\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^other\.example\.com$
RewriteCond %{REQUEST_URI} !^/?(js|resources|image)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


RewriteCond %{HTTP_HOST} ^image\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^other\.example\.com$
RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js)$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
这里可能有一些不必要的或多余的规则,我需要一些帮助来找出可能的错误

总而言之,以下是我努力实现的目标:


如果请求是针对图像或其他子域的,请重定向到www,除非请求是针对jpg、gif、png、css或js文件。此外,如果请求是针对图像或其他子域的,并且文件路径包含除js、资源或图像以外的任何内容,请重定向到www

除了不可信任的推荐人之外,实际上不可能区分请求图像的页面与直接加载图像的页面之间的区别。我要做的是在
图像上为404设置一个错误文档。*
站点只重定向到
www
站点,而不在
图像下加载任何您不想加载的内容。
子域。我想这个解决方案的问题是它们不是真正的子域,它们基本上只是普通域的镜像,所以www上的任何内容都可以通过图像或其他方式获得。