Bạn có thể kiểm tra máy chủ và sau đó xử lý này với mod_rewrite tạo ra một chuyển hướng 301 trong một tập tin .htaccess
; mặc dù nếu bạn có quyền truy cập, tốt hơn nếu bạn thực hiện điều này trong httpd.conf
hoặc tệp cấu hình được bao gồm thay thế.
Kịch bản xuất sắc nhất
Kể từ khi nó trông giống như mod_cband muốn một virtualhost khác nhau cho từng lĩnh vực, bạn sẽ thiết lập một cái gì đó httpd.conf
tập tin của bạn như thế này và bao gồm các quy tắc viết lại trong cấu hình riêng của mình. Một số máy chủ web sẽ làm phương pháp này, nơi các trang web tài khoản chính là DocumentRoot
và các trang web khác đều được đặt nằm dưới đó là thư mục:
<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>
Runner lên
Nếu bạn đang sử dụng một nhà cung cấp dịch vụ lưu trữ ở đó, bạn không có quyền truy cập vào các tệp httpd.conf
và chúng chưa thiết lập các miền dưới dạng alias
của tên miền chính (mỗi tên miền có một thư mục riêng), sau đó bạn sẽ viết các quy tắc của mình trong thư mục gốc .htaccess
cho www.mywebsite.com
như này:
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]
overhead Hầu hết
Nếu họ đang sử dụng bí danh (nơi mọi thứ đều có gốc cùng một tài liệu chính xác) sau đó bạn sẽ cần phải kiểm tra tên máy yêu cầu với một tập tin .htaccess
đó là thường được ban hành bởi tất cả:
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]
Nguồn
2013-06-13 05:52:19
Kiểm tra refe rrer là "giải pháp" phổ biến nhất cho điều này - trong dấu ngoặc kép, bởi vì liên kết giới thiệu không đáng tin cậy. – CBroe