我想提供静态图库,我想知道G-WAN是否可以限制指定文件的热链接?
限制图像热链接会很好,但是我真的想知道是否有可能禁止热链接图像但允许热链接图像以'_thumb'(缩略图)结尾?
if image_name_wo_ext end with '_thumb':
allow image hot-linking
else:
disallow image hot-linking
谢谢!
答案 0 :(得分:3)
以下是如何继续:
如果您要将支票限制为* .gif或* .png文件,可以使用G-WAN "connection handler"
或MIME "content-type handler"
来完成此操作:
http_t *http = (http_t*)get_env(argv, HTTP_HEADERS);
static char my_site[] = "www.my_site.com";
if(strcmp(my_site, http->h_referer)) // not my site
{
char *request = (char*)get_env(argv, REQUEST);
if(strstr(request, "_thumb"))
return 0; // 0: Close the client connection
}
return 255; // continue normally
或者,您可以重定向到另一个页面或图像,而不仅仅是关闭连接:
char szURI[] = "http://another-place.org";
xbuf_t *reply = get_reply(argv);
xbuf_xcat(reply,
"<html><head><title>Redirect</title></head>"
"<body>Click <a href=\"%s\">here</a>.</body></html>",
szURI);
// set the HTTP reply code accordingly
int *pHTTP_status = (int*)get_env(argv, HTTP_CODE);
if(pHTTP_status)
*pHTTP_status = 301; // 301:'moved permanently'
// 2: Send a server reply based on a reply buffer/HTTP status code
return 2;