在我的网络服务器中,我有这些文件。我不希望用户找到“p1.jpg
”和“p2.jpg
”的真实路径。
当我在“p1.jpg
”中显示“index.php
”时,如何将原始路径“/images/p1jpg
”隐藏为此类“/photo/p1.jpg
”。有可能吗?
答案 0 :(得分:3)
我对Apache重写没有经验,但您可以在该目录中创建一个.htaccess
文件,其中包含如下所示的行:
RewriteRule ^/photos/(.+).jpg$ /images/$1 [R]
答案 1 :(得分:2)
因此,我认为,这有两个部分。
1)使图像内容隐藏
2)使一个人可以访问photos / somefile.jpg并让服务器提供图像/ somefile.jpg
1)隐藏图片内容/
在images /中创建一个.htaccess
文件,并在其中加入以下内容
Order allow,deny
Deny from all
2)提供文件
在照片中创建一个.htaccess
文件,并在其中加入以下内容
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_.-]+).jpg$ photo.php?image_name=$1
在照片/目录中创建php文件photo.php
<?php
if(isset($_GET['image_name'])){
if(file_exists("../images/" . $_GET['image_name'].".jpg")){
header('Content-Type: image/jpg');
readfile("../images/" . $_GET['image_name'].".jpg");
}
}
我这样做是盲目的,但会在一秒钟内完成测试!