维护 HTTP Referer
我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
重定向
不会保留引荐来源网址,因为浏览器会收到 301 和要打开的新地址。来自手册: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: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.
这是浏览器的问题,不是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
您始终可以在请求开始时将原始引用者存储在管道变量中,然后从那里提取它。
You can always store the original referrer in a pipeline variable at the beginning of the request and just pull it from there instead.
我创建了一种通过 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/
我相信这一切都取决于你如何编写规则。
它可以根据您提供的标志充当“重定向”或“重写”。
1. 重定向
302 将被发送到浏览器,并且它将发起另一个请求(请参阅启用“persist”选项的 Firebug):
2. 重写
浏览器不会发起 302 重定向,因为我们不发送此类标头,但它将屏蔽内容:
在此选项中,如果有人访问“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 ):
2. Rewrite
browser does not initiate a 302 redirect because we don't send such header, but it will mask the content:
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 ...