Forum Moderators: phranque

Message Too Old, No Replies

Folder / Extension Redirect

         

chalkywhite

2:32 pm on Jan 3, 2014 (gmt 0)

10+ Year Member



Happy New year all.

My xmas project was a little website that basically shows a picture you comment and you move on , nothing special.

Images are stored in a folder called "images". I can redirect anyone who accesses that folder to a page of my choice but i CANNOT figure out how to redirect a user to a page if they hit an image from a link directly.

For example if a user shares an image on facebook and another user hits the link they get just the image..no page. Id like them to get to the homepage.

Ive tried RedirectMatch 301 (.*)\.png$ http://www.example.com

But this stops the actual site loading the image also.

Any suggestion would be great.

Thanks

Allen


Edit.

Solved!

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.co.uk [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ [mydomain.co.uk...] [NC,L]

basically allow myself as a refrer but anyone else requesting extensions get sent elsewhere.

lucy24

8:30 pm on Jan 3, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.co.uk [NC]

This line is standard in no-hotlink routines, but the ()? element is actually wrong. If you have a domain-name-canonicalization redirect, the page will be either www.example.co.uk or example.co.uk, with nothing optional about it.

Psst! You forgot to escape the last period in the condition.

Now, some human visitors will figure out that they can bypass the block by pasting the URL into their address bar instead of clicking the link. But there's not much you can do about that.