Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:19:20+00:00 2026-05-30T23:19:20+00:00

So I am trying to redirect all image requests from my server to use

  • 0

So I am trying to redirect all image requests from my server to use a custom PHP script. The PHP script is built into a framework which can be accessed through http://www.domain.com/images/imageNameHere.jpg The user obviously doesn’t know that the image is being served to them. So now the problem is that this method is currently working for the top level of it, but for the back-end it’s causing a lot of issues. For instance if I try to use another PHP function such as getimagesize() on this image I am returned with an error that it can’t open the stream.

Looking further into the matter I noticed that all of the headers for these images are generating 404 not found errors. (Found this out by using header detection tools online and then seeing in the error_log that every image loaded comes up with a 404 not found error) Needless to say I can’t have this, and I need all the requests to be 200’s. I feel like doing this will help to fix the issue.

This is my current .htaccess file, I am not exactly sure how to set it up to pass these images through the system and not treat them as a file but rather as a URI:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

RewriteCond %{HTTP_HOST} ^i.tinyuploadz.com
RewriteRule (.*) http://www.tinyuploadz.com/images%{REQUEST_URI} [NC,L,NS]

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Image rediects?
#RewriteRule /images/(.+)\.jpg /images/$1.jpg [PT]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Fix the CSS an d JS
#RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]

# Do not let people browse our directories
Options -Indexes

Here is how I have my PHP function set up currently (this is the view generated by the controller)

$day = date("d", $image['upload_time']);
$month = date("m", $image['upload_time']);
$year = date("Y", $image['upload_time']);
$url = IMAGE_URL .  $year . '/' . $month . '/' . $day . '/' . $image['image_id'] . '.' . $image['extension'];

header('Content-type: ' . $image['mime']);
switch ($image['extension'])
{
    case 'png':
        $img = @imagecreatefrompng($url);
        imagepng($img);
        imagedestroy($img);
        break;
    case 'jpg':
    case 'jpeg':
        $img = @imagecreatefromjpeg($url);
        imagejpeg($img);
        imagedestroy($img);
        break;
    case 'gif':
        if (is_ani($url))
        {
            readfile($url);
            break;
        }
        $img = @imagecreatefromgif($url);
        imagegif($img);
        imagedestroy($img);
        break;
    case 'bmp':
        // Seems like we can't do anything special for bmps
        readfile($url);
        break;
    default:
        readfile($url);
        break;
}
//readfile($url . $image['image_id'] . '.' . $image['extension']);

// We don't want Kohana to break anything else with the header change
exit();

function is_ani($filename) 
{
    if(!($fh = @fopen($filename, 'rb')))
        return false;
    $count = 0;
    //an animated gif contains multiple "frames", with each frame having a 
    //header made up of:
    // * a static 4-byte sequence (\x00\x21\xF9\x04)
    // * 4 variable bytes
    // * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)

    // We read through the file til we reach the end of the file, or we've found 
    // at least 2 frame headers
    while(!feof($fh) && $count < 2) 
    {
        $chunk = fread($fh, 1024 * 100); //read 100kb at a time
        $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
    }

    fclose($fh);
    return $count > 1;
}

Thanks for any help on the matter 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:19:21+00:00Added an answer on May 30, 2026 at 11:19 pm

    Try changing this:

    #RewriteRule /images/(.+)\.jpg /images/$1.jpg [PT]
    

    To this:

    RewriteRule /images/(.+)\.jpg /images/$1.jpg [PT,L]
    

    What I suspect is that the Apache parses the rewrite rule, but then only filters it back on the RewriteRule .* index.php/$0 [PT] line, so it’s really passing everything to index.php in the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to redirect all requests which have /blog/? to /?... and use the
I'm trying to internally redirect all requests to index.php and externally redirect all requests
I'm trying to redirect all requests to a domain from a particular user-agent to
I'm trying to redirect all requests to my domain to another domain using mod_rewrite
I am trying to redirect ALL requests for mydomain.com whether they are something like:
I am trying to redirect all requests to domain.com/drupal to domain.com, including all sub
I'm trying to redirect all requests for a subdirectory and any files in it
I'm trying to make a general rewrite rule to redirect all domain.com requests to
I am trying to redirect all traffic through index.php. Here is my .htaccess file:
I'm trying to get my .htaccess to redirect all requests to the /blogs directory,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.