Htaccess redirect

software development

#1

I cant seem to get this right. Im trying to use “rewriteRule” instead of “redirect” to make it seem like images are located in the same directory, but are really on another subdomain.

EX: When you click the properties of an image on a webpage it will say the location is domain.com/img01.jpg but the image is really located at sub.domian.com/img01.jpg

I can use “redirect” but the more images i have the more lines in the htaccess. I want to try and make it alot shorter. Ive done many different strings ive found but cant come up with anything that works from a webpage. after searching last night and all this morning i still cant get it, all i can find is “hot link protection” which i even tried to use.

here was something i was trying to work with.
RewriteRule .(jpg)$ http://sub.domain.com/$1 [L]

When i try to view a jpg from the directory, it takes me to sub.domain.com/jpg It doesnt put the name of the image

Thanks for any replies/views!


#2

You can only do transparent URL rewriting on the same host/domain name. You’re always going to get a redirect if the target is on a different host.

Look into RedirectMatch for something this simple. It doesn’t have the overhead of mod_rewrite but you’ll still be able to use regular expressions so you won’t have to add every image individually.


If you want useful replies, ask smart questions.


#3

Thank you for your reply and help.