Avatar of Roberto Parker
Roberto ParkerFlag for Mexico

asked on 

htaccess image to trigger php script

I have a site and I want to use htaccess run a script when and image is loaded in the site. I have used  <img src="http://mysite.com/script.php> and it works

I need <img src="http://mysite.com/image.png>

And have it run the script  at mysite when the image is opened at the site. I guess htaccess is the way to go
PHP* htacces

Avatar of undefined
Last Comment
Julian Hansen
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

RewriteEngine On
# you might need to change this if not in the root
RewriteBase /
# You might need to add paths to script.php if not in the root
RewriteRule \.(jpe?g|gif|png)$ script.php [L]

Open in new window

Avatar of Roberto Parker

ASKER

RewriteRule \.(jpe?g|gif|png)$ script.php [L]

Runs for all the jpe?g|gif|png ? If I only want one:

RewriteRule \image.png$ script.php [L]

Whats does the (L)  stand for?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Just for PNG and if you want to pass the name of the file into the script then you can do this.
RewriteRule ((.*).png)$ reflect.php?name=$1 [L,NC,QSA]

Open in new window


Avatar of Roberto Parker

ASKER

$1 stands for the name of the image? like image.png or just image?


ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo