获取请求主机 Apache htaccess 的变量?

Getting variable of requesting host Apache htaccess?

我有下面的代码,我可以使用下面的代码来设置一个变量:

SetEnvIf Host (.*) custom_host=

我要的是请求的一个变量host/computer.

例如,如果网站 http://example.com:32/welcome 正在发出请求,我想要这个作为变量?

您需要 Referer 而不是 Host 来访问在请求中发送的 HTTP Referer header。例如:

SetEnvIf Referer (.*) custom_referer=

但是,根据您使用的 server-side 脚本语言,您很少需要将其分配给另一个变量。一般可以根据需要直接引用。

另请注意,可能未设置 HTTP Referer header。引用站点和用户的浏览器都可以阻止它。

更新:

how can i have just the protocol, domain and host without the path.

尝试将正则表达式更改为:

SetEnvIf Referer ^(https?://[^/]+) custom_referer=

如果 Refererhttp://example.com:32/welcome,那么这应该导致 http://example.com:32 被存储在 custom_referer 变量中。