Search code examples
.htaccesshttp-redirectreferer

Redirect .htaccess and check refferer


I need help to write an .htaccess file for Apache to check referer that only allows mydomain referer, otherwise redirect with a 303 response.

Ex: my domain: domain1.com

I want

  1. when the user connect -> http://image.domain1.com/1.jpg
  2. Check referer.
  3. If vaild - > Redirect 303 / http://image.domain2.com/

Any help would be appreciated.


Solution

  • I've been looking for something similar to this, but as @jwd stated, many tutorials show you how to do this.

    Something like this would do what you want, but if you don't know any htaccess at all its best to learn that first. Otherwise the following won't mean anything to you.

    RewriteCond %{HTTP_REFERER} http://image.domain1.com/ [nc]
    RewriteRule ^(.*).jpg$ http://image.domain2.com/$1.jpg [r=303,nc]
    

    This will simply redirect an image from http://image.domain1.com/ to http://image.domain2.com/

    So http://image.domain1.com/1.jpg would redirect to ttp://image.domain2.com/1.jpg if the referrer was from http://image.domain1.com