您可以檢查主機,然後用mod_rewrite建立在.htaccess
文件301重定向處理這一點;雖然如果你有訪問權限,如果你在httpd.conf
或者包含的配置文件中這樣做,會更好。
最佳情況
因爲它看起來像mod_cband希望爲每個域不同virtualhost,你會設置你的httpd.conf
文件這樣的事情,包括在配置本身重寫規則。
<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>
亞軍
如果您正在使用的主機服務提供商:其中主帳號部位是DocumentRoot
和其他網站都嵌套在它的目錄中有些主機會做這種方法其中,您無權訪問httpd.conf
文件,並且他們沒有將域名設置爲主域的alias
(每個域都有一個單獨的文件夾),那麼您可以在根.htaccess
中爲www.mywebsite.com
編寫規則,如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]
檢查refe rrer是最常見的「解決方案」 - 因爲引用是不可靠的。 – CBroe