您可以检查主机,然后使用mod_rewrite 在.htaccess 文件中创建301 重定向来处理此问题;尽管如果您有访问权限,最好在 httpd.conf 或包含的配置文件中执行此操作。
最佳方案
由于看起来mod_cband 想要为每个域使用不同的virtualhost,因此您可以像这样设置httpd.conf 文件并在配置本身中包含重写规则。一些网络主机会这样做,其中主帐户站点是DocumentRoot,其他站点都嵌套在它的目录下:
<VirtualHost *:80>
ServerName www.mywebsite.com
DocumentRoot /home/mywebsite/
RewriteEngine on
RewriteRule ^/files/videos/(.*)$ http://video.mywebsite.com/$1 [R=301,L]
RewriteRule ^/files/images1/(.*)$ http://image1.mywebsite.com/$1 [R=301,L]
RewriteRule ^/files/images2/(.*)$ http://image2.mywebsite.com/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:80>
ServerName video.mywebsite.com
DocumentRoot /home/mywebsite/files/video/
</VirtualHost>
<VirtualHost *:80>
ServerName image1.mywebsite.com
DocumentRoot /home/mywebsite/files/images1/
</VirtualHost>
<VirtualHost *:80>
ServerName image2.mywebsite.com
DocumentRoot /home/mywebsite/files/images2/
</VirtualHost>
亚军
如果您使用托管服务提供商,您无权访问 httpd.conf 文件,并且他们没有将域设置为主域的 alias(每个域都有一个单独的文件夹),然后您将在根.htaccess 中为www.mywebsite.com 编写规则,如下所示:
RewriteEngine On
RewriteRule ^(files/videos/.*)$ http://video.mywebsite.com/$1 [R=301,L]
RewriteRule ^(files/images1/.*)$ http://image1.mywebsite.com/$1 [R=301,L]
RewriteRule ^(files/images2/.*)$ http://image2.mywebsite.com/$1 [R=301,L]
开销最大
如果他们使用别名(其中所有内容都具有完全相同的文档根目录),那么您需要使用所有人通常制定的 .htaccess 文件检查请求的主机名:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^video.mywebsite.com$
RewriteRule ^(files/videos/.*)$ http://video.mywebsite.com/$1 [R=301,L]
#Check to make sure if they're on the video domain
#that they're in the video folder otherwise 301 to www
RewriteCond %{HTTP_HOST} ^video.mywebsite.com$
RewriteCond %{REQUEST_URI} !^/files/videos [NC]
RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L]
RewriteCond %{HTTP_HOST} !^image1.mywebsite.com$
RewriteRule ^(files/images1/.*)$ http://image1.mywebsite.com/$1 [R=301,L]
#Check to make sure if they're on the image1 domain
#that they're in the images1 folder
RewriteCond %{HTTP_HOST} ^image1.mywebsite.com$
RewriteCond %{REQUEST_URI} !^/files/images1 [NC]
RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L]
RewriteCond %{HTTP_HOST} !^image2.mywebsite.com$
RewriteRule ^(files/images2/.*)$ http://image2.mywebsite.com/$1 [R=301,L]
#Check to make sure if they're on the image1 domain
#that they're in the images2 folder
RewriteCond %{HTTP_HOST} ^image2.mywebsite.com$
RewriteCond %{REQUEST_URI} !^/files/images2 [NC]
RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L]