Serving images from subdomains


#1

I’ve got a dev site, and a prod site. The dev site is a subdomain of dreamhosters.com, while the prod site has its own fully hosted domain.

I’m looking to move images from the core site to a subdomain. For prod, I will create a subdomain, serving images for mysite.com from i.mysite.com. I expect that this will not be a problem.

OTOH, I was not allowed to create a subdomain of the testing site (i.e. i.mydevsite.dreamhosters.com). As such, I created a new parallel subdomain, mydevsitei.dreamhosters.com (note the ‘i’ at the end of mydevsite) and moved my images there.

As one would hope, hotlinking is prevented (presumably from any domain other than a subdomain of the domain in question). But I thought I could override that in the .htaccess file in mydevsitei.dreamhosters.com

Here is what I tried:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?mydevsite.dreamhosters.com(/)?.$ [NC]
RewriteRule .
.(gif|jpg|jpeg|bmp|png)$ - [F,NC]

Am I doing something wrong, or is serving images from another domain just not possible given DH’s configuration?


#2

There’s nothing in place by default to restrict hotlinking. If you can’t embed your images right now, then there’s something else wrong with them…


#3

Yeah, I figured that out… I was misinterpreting the 404s, and I was not actually redirecting my image requests

I think this is what I should be doing, but it doesn’t seem to be working:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mysite.com [NC]
RewriteRule .(jpg|jpeg|png|gif|bmp)$ http://mysitei.com/$1 [R=301,L]


#4

I got it

RewriteCond %{REQUEST_URI} ^/images
RewriteRule .(jpg|jpeg|png|gif|bmp)$ http://mysitei.com/%{REQUEST_URI} [R=301,L]