RewriteRule header Content-Type: image/jpeg

362 Views Asked by At

My site, parsing image from another site, but don't show them. (It shows: ����������������� )

I know what it is, it is a problem with Content-Type. I need to use Content-Type: image/jpeg, and all will be ok!

But images are opened by URL (eg. example.com/DIR1/(100000-999999)/DIR2/(100000-999999)/). This number is random.

If I write in .htaccess (on example.com) the following then it works:

Header set Content-Type: image/jpeg - i see photo .

But then all other URLs fail!

How can I : If DIR1/(.*)/DIR2/(.*)/ - Use Content-type: image/jpeg ?

DIR1 , DIR2 = Photos/(number)/image/(number)

1

There are 1 best solutions below

0
MrWhite On

Your script that serves the image should really be generating this header as part of the response.

However, to set this conditionally in .htaccess just for this form of URL-path then you could do something like this:

# Set env var if required URL-path is requested
SetEnvIf Remote_URI "^/DIR1/\d+/DIR2/\d+/$" SET_JPG_CONTENT_TYPE=1

# Only set header when env var is set
Header set Content-Type "image/jpeg" env=SET_JPG_CONTENT_TYPE