代码块:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} mysite.000webhostapp.com$ [NC]
RewriteCond %{HTTP_HOST} !folder1
RewriteRule ^(.jpg)$ http://mysite.00xxxtapp.com/folder1/$1 [R=301,L]
我想你也想在你的文件名出现在新的网址中?(不仅仅是".jpg"(
RewriteRule ([^/]+.jpg)$ http://mysite.00xxxtapp.com/folder1/$1 [R=301,L]
或RewriteRule ([^/]+.jpg)$ /folder1/$1 [L]
如果您想继续看到旧网址
编辑
所以你需要超过 1 个重写规则。
我建议的步骤
- 所有"假"URL重定向到某些PHP脚本
- /folder1/中的所有图像必须重定向或使其无法访问(建议:将它们放在文档根目录之外|(
RewriteEngine On
# all images in somefolder will be parsed through a php script
RewriteRule somefolder/([^/]+.jpg)$ /imageshower.php [L]
# redirect to a no access image
RewriteRule folder/*.jpg /no-access.jpg [R]
php脚本将能够进行一些检查,例如"用户是否登录?"或者他是否拥有权限。
<?php
$filename = basename($_SERVER['REQUEST_URI']); // this still points to the jpg
if(is_file('folder/'. $filename) && is_allowed($user, $filename)) {
header('Content-Type: images/jpg'); // or other like .gif or .pdf etc
readfile('folder/'. $filename);
}
?>