簡體   English   中英

是否可以從 SSI 設置 http 標頭?

[英]Is it possible to set http headers from SSI?

我對 static html 頁面有此配置,其中重定向也是從平面文件完成的:

舊位置。html

<!-- {new-location.html} -->
<!DOCTYPE html>
<html>
<head>
<title>Redirecting to new location</title>
<link rel="canonical" href="new-location.html" />
<meta name="robots" content="noindex, follow">
<noscript><meta http-equiv="refresh" content="0;URL='new-location.html'" /></noscript>
<script>window.location = "new-location.html"</script>
</head>
<body>
<a href="new-location.html">[old-location.html moved here]</a>
</body>

html 應該僅用作優雅的后備鏈,而第一行的注釋是正確的http重定向的配置掛鈎,由於沒有運行時環境,因此需要由網絡服務器完成。

目前我在 Openresty 中使用 Lua 的匹配模式執行此操作,找到新位置,然后將其設置為 301 重定向。

header_filter_by_lua_block { 
local address = ngx.var.document_root .. ngx.var.document_uri
local file = io.open(address, "rb")
local content = file:read(100)
file:close()
local location = string.match(content, "{(%g+)}")
ngx.header['location'] = location
ngx.status = 301
}
-- ideally I should intercept the response body and spare the extra file read, but it seems that even with Lua this is not possible

然而,並不是每個人都接受切換到新的網絡服務器。 所以我想知道是否有一種方法可以使用現成的 Nginx 或者更好的是,使用大多數/所有網絡服務器支持的通用方法。

由於服務器端包括(有沒有辦法從文件中檢索 ssi 變量並將其設置為 header?)和sub_module (用一些正則表達式替換除所需部分之外的任何內容,也許?)兩者都已經解析了整個正文,我認為可能有一種方法,但我不知道從哪里開始尋找。

沒有內置方法可以從 SSI 設置 HTTP 標頭,但您可以使用 CGI 程序來執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM