.htaccess在开发/生产服务器上传递$ 1的不同值

时间:2012-03-05 23:15:46

标签: php apache .htaccess

我正在使用.htaccess来保护文件,除非用户已登录,并且遇到了一个我无法弄清楚的奇怪行为。 .htaccess文件位于名为“secure”的文件夹中,内部是子文件夹。在我的本地开发环境(Mac OS X 10.6)中,$ 1值包括安全之后的整个路径(例如:/ckfinder/files/test.pdf),但我们的CentOS生产服务器上完全相同的代码只传递文件名(test。 PDF)。这是一个apache设置吗?

这是htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ /full/path/to/parser/parse.php?file=$1 [NC]
</IfModule>

如果它对任何人有帮助,这里是检查登录状态并返回文件内容或消息的php代码:

session_start();
if ( $_SESSION['valid_user'] )
{ 
#get the file extension
$filepathbits = explode('/', $_REQUEST['file']);
$filepathbits = array_reverse($filepathbits);
$filebits = explode('.', $filepathbits[0]);
$filebits = array_reverse($filebits);
$ext = $filebits[0];

$filepath = $_SERVER['DOCUMENT_ROOT'].'/secure/'.$_REQUEST['file'];
header('Content-type: application/'.$ext);
header("Content-Disposition: inline; filename=".$filepath);
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Pragma: anytextexeptno-cache', true);
header('Cache-control: private');
header('Expires: 0');
readfile($filepath); 
} else {
echo '<h1>Request denied. You must be logged in to view this content.</h1>';
}

因此,在我的OS X服务器上,它可能会传递/ckeditor/files/test.pdf并显示该文件,而在prod上它会尝试查找/test.pdf并失败。这是我第一次在这里发帖提问...提前谢谢!

0 个答案:

没有答案