Mobile app version of vmapp.org
Login or Join
Cofer257

: How do I redirect direct image paths to my website? I recently noticed that some of the images on my Wordpress website are the pages with the most visits according to Google Analytics. The

@Cofer257

Posted in: #GoogleAnalytics #Images #Seo #Traffic #WebTraffic

I recently noticed that some of the images on my Wordpress website are the pages with the most visits according to Google Analytics. The images could be accessed by clicking them. The result was the pages being opened in a separate tab (no lightbox etc.). I now deactivated this so now one has to right-click and say "open image in new tab" to get the same results as before. Still I'd like to know how this happens and how I can redirect someone who is accessing the direct image path to the page where the image in on?

I noticed YoastSEO is adressing this issue here: kb.yoast.com/kb/redirect-image-attachment-urls/ But it does not work for me.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Cofer257

1 Comments

Sorted by latest first Latest Oldest Best

 

@Welton855

This is possible if each image has an owning page and there is a known pattern between them.

Let's say there is an image called: car.jpg and it is owned by page car.html. In this case you can use the .htaccess to do the conversion using referral detection:

RewriteCond %{HTTP_REFERER} !^https://www.example.com/.*$ [NC]
RewriteRule ^(.*).jpg$ .html [R=301,L]


This means that anyone not loading the image from a page on your site (www.example.com) will get a redirect to the corresponding page of the same name. You can add other types of images too, say jpg and png by changing the regular expression to ^(.*).(jpg|png)$ or redirect to a more complex URL such as post.php?image=

Now if you have images with names that do not relate to any pages such as car.html having an image called nissan_sentra.png then you will not be able to have an easy mapping and you will have to make a redirect table for each case which is not just more complicated but also rather hard to maintain.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme