carbide20 Posted October 5, 2012 Share Posted October 5, 2012 Okay, so I have a website. My images are stored in /images. When someone links to an image on my site from somewhere on the web, I want them to be redirected to a file (image.php) that handles redirecting them to a page that shows the image. This way any user linking to one of my images ends up linking the user to my page that contains that image. My problem is that when I implement the following line in my htaccess, internal images - that is to say anchors on all of my pages break. Is there a way to check if a user is on, say index.php and allow images to be linked to, but if a user is just plain trying to view that image without being inside any other file, to make the redirect happen? RewriteRule ^images/([^\s]+(\.(?i)(jpg|png|gif|bmp))$)$ image.php?id=$1 [R=301,NC,L] I have tried everything I've seen online and am out of ideas. There is really only one file that DOES need the image anchors, so I wouldn't be terribly disappointed if the code was just a manual whitelist of files or something of that sort. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/269104-htaccess-tough-one/ Share on other sites More sharing options...
jonsjava Posted October 28, 2012 Share Posted October 28, 2012 The best solution would be to set a rewrite condion that says "If not from MY site, follow this rule": (change example\.com to your site) RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com(/.*)*$ [NC] RewriteRule ^images/([^\s]+(\.(?i)(jpg|png|gif|bmp))$)$ image.php?id=$1 [R=301,NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/269104-htaccess-tough-one/#findComment-1388221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.