apache 维护 HTTP Referer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2072947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:38:06  来源:igfitidea点击:

Maintain HTTP Referer

apacheredirecthttp-referer

提问by Neil Albrock

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

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

Redirect /Name/register /login.html

重定向/名称/注册/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 引荐来源网址?似乎默认情况下,Apache 会丢弃这些信息。如果在重定向完成后推荐人说:

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

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

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

任何人,如果这甚至可能吗?如果没有,请考虑替代方案。

Many thanks, Neil

非常感谢,尼尔

回答by Pekka

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

Redirect不会保留引荐来源网址,因为浏览器会收到一个 301 和一个要打开的新地址。从手册

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

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

mod_rewriteand (I think) Aliascan 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.

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

回答by docwhat

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.

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

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

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

回答by kprobst

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

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

回答by Evgeny

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

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

回答by Ricky Levi

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

1. 重定向

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

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

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

2. Rewrite

2. 重写

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

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

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"

在此选项中,如果有人访问“page.html”,他将看到“index.html”的内容而不是“page.html”,但上面的 URL 仍会显示“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 ...

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