繁体   English   中英

.htaccess重定向直接访问

[英].htaccess redirect direct access

我试图阻止用户直接访问我网站上的文件。 基本上我有一个位于/images/header.jpg的图像

我正在尝试使用.htaccess将所有尝试直接访问该文件“http://www.domain.com/images/header.jpg”转发到我的404页面但我希望从我的调用时仍然加载图像源代码。 使情况复杂化的是我实际上将header.jpg重定向到另一个图像文件夹。

所以最终期望的效果是:

用户加载页面 - > header.jpg被调用并重定向到new_header.jpg用户尝试链接header.jpg从他们的网站 - >他们被重定向到我的404页面。

我尝试了一些条件,但未能达到预期的效果......

RewriteCond %{REQUEST_URI} ^/images
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule ^(.*\header.jpg(/.*)?)$ new_header.jpg [L,QSA]

我认为这样的事情对你有用:

RewriteEngine On
#Redirect all request for things in /images that don't come from website to 404 page (assumed to be /404 in this case) - Prevents hotlinking
RewriteCond %{REQUEST_URI} ^/images
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain\.com [NC]
RewriteRule ^.*$ /404 [L,R=404]

#Redirect requests for /images/header.jpg to new_header.jpg image
RewriteRule ^/?images/header.jpg /path/to/other/images/new_header.jpg [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM