I want to redirect those who are trying to open the image directly from the URL to the php page:

Example: This Link

www.mydomain.com/images/test-image-1.jpg 

need to redirect (redirect) to

 www.mydomain.com/newpage/test-image-1.jpg 

I already have a sample code but it does not work, somewhere was wrong

 RewriteCond %{HTTP_ACCEPT} text/html RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain\.com [NC] RewriteCond %{HTTP_USER_AGENT} !(adsBot-google|googlebot-mobile|googlebot|googlebot-image|msnbot|psbot|yahoo-mmcrawler|bingbot|bingpreview|Adidxbot|yandexbot|baiduspider) [NC] RewriteRule ^images/([^/]+)/? /newpage/$1 [R=302,L] 

    1 answer 1

     RewriteEngine On RewrieRule /images/ /newpage/