0

我有一个网站,我试图限制用户访问根文件夹(即当用户键入https://example.com/img/image.png时显示被阻止的内容消息)。我在 .htaccess 上编写了以下代码:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^https://(\.)?domain.com [NC] 
RewriteCond %{HTTP_REFERER} !^https://(\.)?domain.com.*$ [NC]
RewriteRule \.(gif|jpg|js|txt|png)$ /messageforcurious [L]

起初这很有效,但现在我的 html 文件上的元标记似乎找不到 og-image,显然是因为我刚刚写的限制。这是我的元标记。

<meta property="twitter:image" content="https://example.com/img/image.png">

有没有办法阻止用户直接访问图像而不影响元标签?

我尝试使用图像的相对位置:

<meta property="twitter:image" content="img/image.png">
4

1 回答 1

0

你可以试试这个

这将阻止直接访问所有文件和文件夹。

deny from all

到特定的文件类型

<Files ~ "\.png$">
Order allow,deny
Deny from all
</Files>
于 2019-07-17T19:23:07.827 回答