Forum Moderators: phranque

Message Too Old, No Replies

combining redirection with hotlink protection

         

Aleister

12:45 am on Dec 20, 2004 (gmt 0)

10+ Year Member



Lets say my main site is mainsite.com. I used to have another popular site on this domain, called 'subsite', which was located in the 'subsite' directory of 'mainsite'. Well I moved subsite to its own domain.

I am using the following redirect code in the .htaccess file of mainsite, so that people who still have old links to subsite can just be redirected to the new subsite:


redirectMatch 301 ^/subsite/(.*) http://www.subsite.com/$1
redirectMatch 301 ^/subsite http://www.subsite.com/$1

This code works great. I also have hotlink prevention code in the mainsite .htaccess file:


RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mainsite\.com [NC]
RewriteRule \.(gif¦jpe?g)$ - [NC,F]

Now the problem is, if someone has a hotlink (href not img of course - or else it would not be a link) to an image on the old location of subsite (mainsite.com/subsite). They click on it, and it takes them too the error page for mainsite, because of the hotlink prevention code.

What I would prefer, is that if the link points to the old location of subsite, they instead see the error page for the new subsite. Because there would be a better chance of them checking out subsite. If they come for subsite but get an error page for mainsite, they might give up.

There may not be a way to do this, but is it possible to 'force' the redirection code to work before the hotlink prevention code does?

This is a weird issue to explain, and it may only make sense if you have done this same thing before.

I _can_ make offsite image links pointing to the old subsite go to the new subsite if I remove hotlink protection code for mainsite, but I don't really want to do that.

Any thoughts? Anyone still reading? ;)