维护 HTTP Referer

发布于 2024-08-17 19:46:50 字数 356 浏览 4 评论 0原文

我已经在 Apache 服务器上设置了一些重定向。它们看起来有点像这样:

Redirect /Name/register /login.html

我的问题是……是否有办法通过此重定向保留 HTTP Referrer?看起来默认情况下,Apache 会丢弃这些信息。 我真的很喜欢。

如果重定向完成后引用者说: http://the.orginalurl, com/Name/register

有人知道这可能吗?如果没有,请考虑替代方案。

非常感谢, 尼尔

I've setup some redirects on an Apache server. They look at bit like this:

Redirect /Name/register /login.html

My question is this... is there anyway to preserve the HTTP Referrer through this redirect? It would seem that by default, Apache discards the information. I would really like it if after the redirect was complete the referrer was say:

http://the.orginalurl.com/Name/register

Anyone if this is even possible? If not, thoughts on an alternative.

Many thanks,
Neil

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

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

发布评论

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

评论(5

白云不回头 2024-08-24 19:46:50

重定向 不会保留引荐来源网址,因为浏览器会收到 301 和要打开的新地址。来自手册

重定向指令通过要求客户端在新位置重新获取资源来将旧 URL 映射到新 URL。

mod_rewrite 和(我认为)Alias 可以直接重写(即不会导致浏览器重定向)并将保留引荐来源网址。使用 mod_rewrite,如果您愿意,您甚至可以将引用者作为 GET 参数添加到您的请求中。

Redirect won't preserve the referrer because the browser is sent a 301 and a new address to open. From the manual:

The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.

mod_rewrite and (I think) Alias can rewrite directly (i.e. without causing a browser redirect) and will preserve the referrer. With mod_rewrite, you can even add the referer as a GET parameter to your request, if you want to.

甜味拾荒者 2024-08-24 19:46:50

这是浏览器的问题,不是apache的问题。你对此无能为力。这样做是为了防止某些安全问题和引荐垃圾邮件。

http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding

It's a browser issue, not apache. There isn't much you can do about it. This is done to prevent certain security issues and referrer spam.

http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding

云醉月微眠 2024-08-24 19:46:50

您始终可以在请求开始时将原始引用者存储在管道变量中,然后从那里提取它。

You can always store the original referrer in a pipeline variable at the beginning of the request and just pull it from there instead.

黄昏下泛黄的笔记 2024-08-24 19:46:50

我创建了一种通过 301 重定向传输引用者的替代方法。
https://webmasters.stackexchange.com/questions/4665/

I created an alternative way that transfers the refferer through a 301 redirect.
https://webmasters.stackexchange.com/questions/4665/

诗化ㄋ丶相逢 2024-08-24 19:46:50

我相信这一切都取决于你如何编写规则。
它可以根据您提供的标志充当“重定向”或“重写”。

1. 重定向

302 将被发送到浏览器,并且它将发起另一个请求(请参阅启用“persist”选项的 Firebug):

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [R=302,L]

2. 重写

浏览器不会发起 302 重定向,因为我们不发送此类标头,但它将屏蔽内容:

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [L]

在此选项中,如果有人访问“page.html”,他将看到“index.html”的内容而不是“page.html”,但上面的 URL 仍将显示“page.html”

利于维护页面等...不确定登录页面...但这是另一个需要考虑的选择。

在我的具体情况下,“RewriteRule”与“Alias”之间的主要区别在于,重写可以在.htaccess中设置,而“Alias”则不能...所以并不总是可以使用Alias...

I believe it all depends on how you write the rule.
It can act as a "redirect" or a "rewrite" according to the flags you provide.

1. Redirect

302 will be sent to the browser, and it will initiate another request ( see Firebug with the "persist" option enabled ):

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [R=302,L]

2. Rewrite

browser does not initiate a 302 redirect because we don't send such header, but it will mask the content:

RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [L]

In this option, if someone will access "page.html" he will see the content of "index.html" not "page.html" but the URL above will still show "page.html"

Good for maintenance page etc ... not sure about login pages ... but it's another option to think about.

The main difference between the "RewriteRule" vs "Alias" in my specific case, is that the rewrite can be set inside .htaccess while "Alias" does not ... so not always you can use Alias ...

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