I am working in a project where it needs to serve research papers and documents, so while serving the file it need to check few pass, if everything seems good then it should forward the file(research papers).
It would be easy to read the file and stream it using PHP but we need to use the apache xsendfile
to serve the files.
The application works differently, however I have made a small project like this so that we can re-produce the problem.
All requests go to an IP address, and using a .htaccess
file, it will redirect the request to index.php
file.
Here is the htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L,QSA]
XSendFile On
In the index.php
it would decide which file to serve. Here is the code of index.php
:
<?php
$file =
__DIR__
. '/scholar'
. $_SERVER[ 'REQUEST_URI' ]
. 'index.html';
// echo $file;
// exit();
header("Content-type: " . mime_content_type( basename( $file ) ));
header("X-Sendfile: " . $file );
In the $file
variable it will generate the full path of the requested research paper.
- Requested URL:
http://dev.edu/project-1/
- Generated File Path:
/var/www/html/scholar/project-1/index.html
Here the file path is valid, but the file was not found!
Though the error message indicates that the index.php
file was not found but if you uncomment this two line,
// echo $file;
// exit();
you will be able to see that the index.php
file was actually used by apache and it would print the full valid path of the file!
I have tried my best to let you understand the problem, i can't really understand whats the issue that causing this.
Edit: folder tree of /var/www/html/
Edit: xsendfile is installed and enabled