Results 1 to 3 of 3

 

Thread: Redirecting to a new file extension

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Jan 2007
    Location
    I'm somewhere where I don't know where I am
    Posts
    90
    Thanks
    1
    Thanked 0 Times in 0 Posts


    I'm creating a new site where the main content is images, so I'm trying to both prevent hotlinking and monetize visitors that come from image searches.

    When a visitor tries to navigate directly to an image I want them to be redirected to a page which displays the image in a page; the page hosting the image is at the same file address, but with a different extension, e.g.:

    domain.com/folder/01.jpg gets redirected to domain.com/folder/01.php

    I've managed to achieve the first goal of preventing hotlinking with this in the .htaccess file:

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_REFERER} !domain\.com [NC]
    But I haven't been able to find a way to redirect visitors to the new file extension yet . I know its possible because I've seen it done.

    Any help is appreciated.
    'Like dust in the wind.. These are the days of our lives' Waynes World

  2. #2
    buy.at tech

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 11 Posts
    The following should work as you want:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_REFERER} !(domain\.com) [NC]
    RewriteRule (.*)\.(gif|jpe?g|png)$ http://domain.com/folder/$1.php [R,L]
    It's also possible to use the same PHP file for all images:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_REFERER} !(domain\.com) [NC]
    RewriteRule (.*)\.(gif|jpe?g|png)$ http://domain.com/folder/hotlink.php?image=$0 [R,L]
    where hotlink.php contains something like the following:
    PHP Code:
    <img src="<?php echo $_REQUEST['image']; ?>">
    Ian Sproates, Head of Development (Newcastle), buy.at
    tel: +44 (0)191 222 9728 | email: ian.sproates@buy.at | icq: 490-111-853 | msn: sproates@hotmail.com

  3. The Following User Says Thank You to Sproates For This Useful Post:

    user1635 (17-10-09)

  4. #3
    Registered User

    Status
    Offline
    Join Date
    Jan 2007
    Location
    I'm somewhere where I don't know where I am
    Posts
    90
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sproates View Post
    The following should work as you want:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_REFERER} !(domain\.com) [NC]
    RewriteRule (.*)\.(gif|jpe?g|png)$ http://domain.com/folder/$1.php [R,L]
    Awsome, thank you.

    Quote Originally Posted by Sproates View Post
    It's also possible to use the same PHP file for all images:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_REFERER} !(domain\.com) [NC]
    RewriteRule (.*)\.(gif|jpe?g|png)$ http://domain.com/folder/hotlink.php?image=$0 [R,L]
    where hotlink.php contains something like the following:
    PHP Code:
    <img src="<?php echo $_REQUEST['image']; ?>">
    Good point, it would be a lot easier to handle all the images with one PHP file then rewrite the url afterwards.

    Sproates you're a star :tup
    'Like dust in the wind.. These are the days of our lives' Waynes World



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Redirecting to Merchant - Best Way?
    By nickynoodles in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 21-08-09, 04:20 PM
  2. Redirecting Web Traffic, Hlp please
    By msg2004 in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 05-10-08, 12:34 PM
  3. Change HTML file to PHP file
    By internet-laptop in forum Programming
    Replies: 6
    Last Post: 10-07-08, 04:06 PM
  4. Redirecting ASP to another file on Apache
    By DanielCoe in forum Programming
    Replies: 1
    Last Post: 04-08-04, 03:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2