简体   繁体   English

基于http状态代码的重写

[英]rewritecond based on http status code

Is there any way in apache to set a rewrite condition based on what http code response you're getting? 在apache中是否有任何方法可以根据您获得的http代码响应来设置重写条件? The server in front of an oauth proxy (apache) that redirects (302) to my auth provider; 服务器在oauth代理(apache)前面,重定向(302)到我的auth提供者; however I don't want it to proxy anything in the the websocket directory -- I'd rather it 403 instead. 但是我不希望它在websocket目录中代理任何东西 - 我宁愿它代替403。 This is all to prevent it from constantly trying to reauth which it isn't authorized and building up lots of state cookies for OpenIDC. 这一切都是为了防止它不断尝试未经授权的reauth并为OpenIDC构建大量状态cookie。

Thanks for the consideration. 谢谢你的考虑。

Something like this: 像这样的东西:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^my\.server\.co$
RewriteCond %{HTTP_RESPONSE} 302
RewriteCond %{REQUEST_URI}  ^/websocket
RewriteRule (.*) $1 [F,L,NC]

You should be able to use: 你应该可以使用:

<Location /websocket>
    OIDCUnAuthAction 401
</Location>

As documented here in the configuration primitives: 作为记录在这里的配置原语:

# (Optional)
# Defines the action to be taken when an unauthenticated request is made.
# "auth" means that the user is redirected to the OpenID Connect Provider or Discovery page.
# "401" means that HTTP 401 Unauthorized is returned.
# "pass" means that an unauthenticated request will pass but claims will still be passed when a user happens to be authenticated already
# Useful in Location/Directory/Proxy path contexts that serve AJAX/Javascript calls and for "anonymous access"
# When not defined the default "auth" is used.
#OIDCUnAuthAction [auth|pass|401]

(well it would return a 401 status code instead of a 403) (它会返回401状态代码而不是403)

Other solution 其他方案

RewriteEngine on

ErrorDocument 403 /%{REQUEST_URI}/403.shtml
ErrorDocument 404 /%{REQUEST_URI}/404.shtml

RewriteCond %{REQUEST_URI} /([0-9]{3}+).shtml$ [NC]
RewriteRule (.*) $1 [R=%1,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM