Image handling on subdomains

Using a single web hosting account to host multiple sites

Image handling on subdomains

Postby uoitguy » Sun Jul 23, 2006 3:16 pm

I would like all my images to be hosted on images.DOMAIN.COM. When requests for images are made on subdomains (e.g. SUB.DOMAIN.COM/image.gif) these should be redirected to the images subdomain with the original subdomain included in the path (e.g. images.DOMAIN.COM/SUB/image.gif). In addition, if there is no subdomain, I would like the path used to be 'main'. Thanks :)
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby richardk » Sun Jul 23, 2006 3:38 pm

Why don't you just change the paths in the pages?!

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN$ [NC]
RewriteCond %{HTTP_HOST}    ^(.+)\.DOMAIN$ [NC]
RewriteRule ^(.+\.(gif|jpe?g|png))$ http//images.DOMAIN/%1/$1?   [R=301,L]

RewriteRule ^(.+\.(gif|jpe?g|png))$ http//images.DOMAIN/main/$1? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby uoitguy » Sun Jul 23, 2006 4:22 pm

To answer your question of not changing the paths, I would like the images to appear to originate from each subdomain but I would like to manage all images on my site on one subdomain. I have tested the rule you have given me. I found that it produces no errors, but simply a blank page when I request the image. If what I'm doing makes no sense at all, I will just examine a better way to approach this problem. But I thank you once again for your help :)
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby richardk » Mon Jul 24, 2006 5:54 am

Both http//s should be http://.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby uoitguy » Mon Jul 24, 2006 5:57 am

Thanks richardk, can't believe I didn't notice that one. Works like a charm :wink:
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby uoitguy » Sat Jul 29, 2006 7:07 am

I have tried modifying this code slightly so all images are redirected from the images subdirectory. Everything works fine except for when no path is used (e.g. images/test.gif). Then a double slash appears. (http://images.DOMAIN.COM/main//test.gif) Any ideas? Thanks!

Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?DOMAIN\.COM$ [NC]
RewriteCond %{HTTP_HOST}    ^(.+)\.DOMAIN\.COM$ [NC]
RewriteRule ^images/((.+)/)*(.+\.(gif|jpe?g|png))$ http://images.DOMAIN.COM/%1/$2/$3?   [L]
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm

Postby richardk » Sat Jul 29, 2006 7:41 am

Try this RewruteRule:
Code: Select all
RewriteRule ^images(/.+)?(/.+\.(gif|jpe?g|png))$ http://images.DOMAIN.COM/%1$1$2? [L]


EDIT: But if you're going to do that, you could just redirect the whole /images directory:
Code: Select all
RewriteRule ^images/(.+)$ http://images.DOMAIN.COM/%1/$1? [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby uoitguy » Sat Jul 29, 2006 7:44 am

Thanks richardk. Right again, as usual :)
uoitguy
 
Posts: 14
Joined: Sun Jul 16, 2006 12:22 pm


Return to Domain Handling

Who is online

Users browsing this forum: Google [Bot] and 61 guests

cron