是否可以使用 mod_rewrite 仅从 HTTP_REFERER 获取主机名?

发布于 2024-08-22 14:27:47 字数 87 浏览 0 评论 0原文

我试图仅从 Apache 服务器变量 HTTP_REFERER 解析主机名,我想知道 mod_rewrite 是否可以,因为我的目标是获取主机名,然后重写请求。

I'm trying to parse hostname only from the Apache server variable HTTP_REFERER and I'm wondering if it's possible with mod_rewrite since my goal is to obtain the hostname and then rewrite the request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙幽之幻 2024-08-29 14:27:47

你的 HTTP_REFERER 将返回链接到你的页面的确切 URL,无论是否使用 mode_rewrite,它都会返回文字 url。因此,如果是 something.com/foo/index.php 或 somthing.com/foo/action,http_referer 将像显示的那样捕获这些 url。

Your HTTP_REFERER will return the exactly URL that linked to your page, with mode_rewrite or not, it will return the literal url. So, if it is something.com/foo/index.php or somthing.com/foo/action, the http_referer will cat these urls like as appear.

怂人 2024-08-29 14:27:47

我想通了

RewriteCond %{HTTP_REFERER} ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? [NC]
RewriteRule ^traveler.html$ http://something.com/viewer.html?embed_referer=%4 [QSA,L]

通过 RewriteCond 的反向引用,我可以将查询字符串附加到新的路径/URL 中。

I figured it out

RewriteCond %{HTTP_REFERER} ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? [NC]
RewriteRule ^traveler.html$ http://something.com/viewer.html?embed_referer=%4 [QSA,L]

With the back-reference from RewriteCond, I can append the query string to the new path/URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文