apache 如何删除Apache中的cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1798431/
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:26:20  来源:igfitidea点击:

How to remove a cookie in Apache

apachemod-rewriteapache2

提问by Sergey Golovchenko

I need to remove a cookie from the HTTP request that gets to the server. Doing it on the client (that writes this cookie) or on the server (that reads it) is not an option. I have Apache 2.0 that proxies requests between client and the server, so I was hoping to remove the cookie right there in Apache using mod_rewrite.

我需要从到达服务器的 HTTP 请求中删除一个 cookie。在客户端(写入此 cookie)或在服务器(读取它)上执行此操作不是一种选择。我有 Apache 2.0 代理客户端和服务器之间的请求,所以我希望使用 mod_rewrite 删除 Apache 中的 cookie。

My question is, is there a way to remove a certain cookie from the HTTP request using mod_rewrite?

我的问题是,有没有办法使用 mod_rewrite 从 HTTP 请求中删除某个 cookie?

If not possible to remove just onecookie then as a last resort to remove allcookies from the request?

如果不能只删除一个cookie,那么作为最后的手段从请求中删除所有cookie?

I am open to other suggestions of how to accomplish this if mod_rewrite is not the right tool for this task.

如果 mod_rewrite 不是执行此任务的正确工具,我愿意接受有关如何完成此任务的其他建议。

回答by Andy

Apache mod_rewriteallows manipulation of URLs but not of HTTP headers, however 'mod_headers'will let you do that.

Apachemod_rewrite允许操作 URL,但不允许操作 HTTP 标头,但是'mod_headers'可以让您这样做。

So, you could use:

所以,你可以使用:

RequestHeader unset Cookie

This will strip allcookies from the request. I'm not sure if its possible to remove just a particular cookie using this technique.

这将从请求中删除所有cookie。我不确定是否可以使用此技术仅删除特定的 cookie。

Alternatively, you can stop cookies being passed back to the client using:

或者,您可以使用以下方法停止将 cookie 传递回客户端:

Header unset Set-Cookie

if that's more appropriate.

如果那更合适。

回答by Anthony O.

With Apache > 2.2.4, you could have used:

使用 Apache > 2.2.4,您可以使用

RequestHeader edit Cookie "^(.*?)ANY_COOKIE=.*?;(.*)$" 

回答by Vivek Singh CHAUHAN

You can manage specific cookies using following statements in apache reverse proxy configurations:

您可以在 apache 反向代理配置中使用以下语句管理特定的 cookie:

To remove any specific cookie you can use:
'Header add Set-Cookie "ANY_COOKIE='';expires='SOME_DATE_IN_PAST'; Max-Age=0; Path=COOKIE_PATH"'

要删除您可以使用的任何特定 cookie:
' Header add Set-Cookie "ANY_COOKIE='';expires='SOME_DATE_IN_PAST'; Max-Age=0; Path=COOKIE_PATH"'

By specifying past date, you tell the browser that the cookie has expired and browser will discard the cookie.

通过指定过去日期,您告诉浏览器 cookie 已过期,浏览器将丢弃 cookie。

To add any cookie you can use:
'Header add Set-Cookie "ANY_COOKIE='ANY_VALUE';expires='SOME_FUTURE_DATE'; Path=COOKIE_PATH"'

要添加您可以使用的任何 cookie:
' Header add Set-Cookie "ANY_COOKIE='ANY_VALUE';expires='SOME_FUTURE_DATE'; Path=COOKIE_PATH"'

Be sure that you specify the some future date. If you do not specify any date, the cookie will be treated as session cookie.

请务必指定某个未来日期。如果您不指定任何日期,cookie 将被视为会话 cookie。

Try using the following to remove specific cookie from request:

尝试使用以下方法从请求中删除特定的 cookie:

'RequestHeader add Cookie "ANY_COOKIE='';expires='SOME_PAST_DATE'; Path=COOKIE_PATH"'

'RequestHeader 添加 Cookie "ANY_COOKIE='';expires='SOME_PAST_DATE'; Path=COOKIE_PATH"'

回答by Dylan B

I use this to unset all cookies (good to serve static content)

我用它来取消设置所有 cookie(适合提供静态内容)

Header unset Cookie
Header unset Set-Cookie