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 7772531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:54:40+00:00 2026-06-01T16:54:40+00:00

Essentially, what I am doing is intercepting a 404 using ErrorDocument in .htaccess, and

  • 0

Essentially, what I am doing is intercepting a 404 using ErrorDocument in .htaccess, and pointing it at getFile.php. getFile then grabs the file name out of the url and searches for it in the mysql database, getting the data and applying appropriate headers.

In my dev environment (up-to-date LAMP server running under ubuntu) everything seems to work fine, but the site is being hosted on GoDaddy, and there seems to be some issue with the headers returned. I think GoDaddy returns a 404, then sends the data anyway.

The result is when I right click on a link that is to be handled in this manner, I can ‘Save As’, and everything works fine. If the file is an image, it opens no problem. But if I just click the link and it is a file that is to be downloaded rather than viewed in a browser, I get ‘File Not Found’ errors, across all browsers. Firebug Console claims it is a 404 error, regardless of whether the file successfully transfers. My code is the following:

$folder = explode( "/" , $_SERVER["REQUEST_URI"] );
$pageName = $folder[sizeof($folder)-1];

$sql = "SELECT data, mimeType, OCTET_LENGTH(data) AS size FROM tblFiles WHERE fileName = '".$pageName."' AND active=1;";

$result = mysql_query("$sql") or die();

$data = mysql_fetch_array($result);

header("HTTP/1.0 200 OK");
header("Content-Type: ".$data['mimeType']);
header("Content-Length: ".$data['size']);

echo $data['data'];

And the .htaccess file:

ErrorDocument 404 /FILES/dbFiles/getFile.php

Now this is the full .htaccess file present at /FILES/dbFiles. I don’t know if GoDaddy is expecting more stuff in there, but it seems to work just as written on my own server.

I’ve tried numerous combinations of header info with no positive effect.

My code apparently works, but I can’t seem to prevent that 404 from happening.

Thanks!
-Jer

  • 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-06-01T16:54:41+00:00Added an answer on June 1, 2026 at 4:54 pm

    Try this in your /FILES/dbFiles/.htaccess file (without the ErrorDocument part):

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ getFile.php?file=$0 [QSA,L]
    

    This will direct all non-existing URLs to your getFile.php script without generating a 404. Make sure you do output a 404 if the script does not find the content in your database.

    Inside your PHP file, use:

    if(@$_GET['file']) {
    
        //Your code here.  Use $_GET['file'] instead of $_SERVER["REQUEST_URI"]
    
    } else {
        //Weird.  This file was directly accessed.
        die();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm essentially doing is creating a list item on drop. Using the drop
I have a Client/Server application written Delphi. Essentially all the application is doing is
Essentially, I am doing some of the development for my Django app straight on
I'm doing some unit tests where essentially I need the input stream to block
I'm doing a C homework project and I'm incredibly lost. Essentially, I have to
Essentially what i am doing is finding a piece of text in a textfile.
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially I have a method of a class called killProgram, which is intended to
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
Essentially I'm wondering if the following can be done in Ruby. So for example:

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.