使用.htaccess在一段时间后重定向图像


I am trying to redirect direct image link http://example.com/image1.png
after 5 sec to other url http://exampleurl.com
But i can't do it.
If i say more clearly, when user click direct image, its show direct image 5 sec and after 5 sec finished its redirect to other url.

I used below code:

HTML Code:

<html>
<head>
<meta http-equiv="REFRESH" 
content="<?php echo $_GET['delay'];?>;URL=<?php echo $_GET['target'];?>">
</head>
</html>

htaccess Code:

RewriteEngine On
RewriteRule ^image1\.png$ redirect.php?delay=5&target=http://exampleurl.com [L,NC]

Please Help Me To Solve It. Thanks.

HTTP redirect is a header directive, and headers cannot be modified after body is sent. That is why it is not possible.

A redirect after 5 seconds can only be achieved using some client side code in JavaScript.

You could add an .htaccess RewriteRule to a php script with image as a parameter. In the php script, just display the image in an img tag using data uri. If you use same image path in img src, it will apply same RewriteRule.

Below the img tag, write a JavaScript to redirect to the desired URL in a setTimeout to 5000 milliseconds.