Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess临时重写规则_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess临时重写规则

Php htaccess临时重写规则,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我目前在使用.htaccess重定向客户端时遇到了一个小问题:通过“短暂的”链接和指向不同内容的唯一链接(使用不同的路径和扩展名) 让我用我已经得到的一些代码来解释一下 .htaccess: RewriteEngine on RewriteRule (.+?)$ call.php?code=$1 [L,QSA] call.php: <?php require_once("encryption.php"); if(isset($_GET['code'])) {

我目前在使用.htaccess重定向客户端时遇到了一个小问题:通过“短暂的”链接和指向不同内容的唯一链接(使用不同的路径和扩展名)

让我用我已经得到的一些代码来解释一下

.htaccess:

RewriteEngine on
RewriteRule (.+?)$ call.php?code=$1 [L,QSA]
call.php:

<?php
require_once("encryption.php");

if(isset($_GET['code']))
{
    // decryption of the code
    // the decrypted code is the content path
    $clearCode = DecryptFunction(htmlspecialchars($_GET['code']));
    
    if(strpos($clearCode, '.php') !== false)
    {
        include($clearCode);
    }
    else if(strpos($clearCode, '.jpeg') !== false)
    {
        $file_path_name = $clearCode;
        $ctype= 'image/jpeg';
        header('Content-Type: ' . $ctype);
        $handle = fopen($file_path_name, "rb");
        $contents = fread($handle, filesize($file_path_name));
        fclose($handle);
        echo $contents;
    }
    else if(strpos($clearCode, '.mp4') !== false)
    {
        $file_path_name = $clearCode;
        $ctype= 'video/mp4';
        header('Content-Type: ' . $ctype);
        $handle = fopen($file_path_name, "rb");
        $contents = fread($handle, filesize($file_path_name));
        fclose($handle);
        echo $contents;
    }
    
}
?>
即使在那里,我也不确定它是否非常有效,服务器上需要一个循环脚本来定期转储env变量

我还介绍了如何创建重写规则映射文件,并在运行中使用php对其进行编辑,但我并不喜欢这种方法

那么,是否可以直接从.htaccess文件调用我的php解密函数,并将客户端重定向到clear路径?还是我没有提到的另一种方法

我确信我完全控制了Apache服务器


提前感谢您的回答:)

如果您的问题是大文件的性能,您可以使用而不是
fopen
/
fread
。“注意:readfile()本身不会出现任何内存问题,即使在发送大文件时也是如此。”您好,我刚刚尝试过它,它工作得很好,但加载大文件仍然需要很长时间,我需要它像直接访问一样工作,并且不需要通过读取文件向服务器收费。无论如何,谢谢你的回答:)并且绝对必须屏蔽原始文件名?您可以使用头()使PHP比
readfile()
更快,但是我不知道它是否泄漏了文件名(没有现成的安装测试)。另请看,在我的例子中是的,必须隐藏内容的原始文件名/路径。所有链接必须是唯一的,一次性使用。此方法与直接访问一样快速,但它共享头中的内容路径,并且可以被客户端读取。。。
<?php
require_once("encryption.php");
$filePath = "some/clear/path/to/encrypt.extension";
$encryptedPath = EncryptFunction($filePath);
putenv("$encryptedPath=$filePath");
?>

<!DOCTYPE html>
<html>
<body>
 <img src = "<?php echo $encryptedPath;?>"/>
</body>
</html>
RewriteEngine on
RewriteRule (.+?)$ %{ENV:$1} [L,QSA]