php - htaccess redirect all images to handler -


what want redirect images (jpeg, png, gifs?) index.php?q=file , handler use <img src=file> tag.
i'm afraid when calling file tag create infinite loop.
i'm asking how redirect outside calls image.
(or there better way protect images?)

that rule creates handler takes matching requests imagehandler.php

please can try rule below;

rewriterule ^(.*)(.jpg|.jpeg|.png|.gif|.bmp|.etc)$ imagehandler.php?f=%{request_filename} [qsa,l] 

and $_get["f"] file name requested , $_get["f"] represents path of file on server.

ps: rule wont cause infinite loop requests imagehandler.php execute processes , can decide return file or not. please mind have implement binary output imagehandler.php can cause cost operations. reduce cost of operation may have implement client-cache or server-cache mechanism imagehandler.php.

that rule creates redirect handler redirects matching requests index.php

rewritecond %{http_referer} ^$ #that means referer empty means direct access file rewritecond %{http_referer} !^http://www\.example\.com.* #that means referer not domain because when use file in <img> tag create request image referer of embedding address rewritecond %{request_uri} !^index.php  #that means request not targeted index.php (which part of endless loop) rewritecond %{request_filename} -f #that means request targeted file rewritecond %{request_uri} (.jpg|.jpeg|.png|.gif|.bmp)$  #that means request ends .ext rewriterule ^(.*)(.jpg|.jpeg|.png|.gif|.bmp|.etc)$ http://example.com/index.php?f=$1 [r=302,l,qsa] #that means redirect request index.php?f=file 

i not have chance test second 1 due not have linux environment production , not possible test in production environment.

hope these information helps situation.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -