apache: basic authentication before rewrite

后端 未结 4 834
花落未央
花落未央 2020-12-17 21:46

I have an Apache in frontend that should redirect a request via a RewriteRule.

I have to put a basic authentication before the request is redirected, so

4条回答
  •  自闭症患者
    2020-12-17 22:16

    I solved putting the rewrite condition and rewrite rule outside the Locatio directive:

    
      AuthType Basic
      AuthName "Restricted Files"
      AuthUserFile /etc/httpd/conf/tag.pwd
      Require valid-user
    
    RewriteCond %{LA-U:REMOTE_USER} !^$
    RewriteRule ^/(.*) http://xxxxxx:xxx/$1   [P,L]
    

    many thanks to h0tw1r3 for the suggestion

    *Keep in mind that Location directives operate on URLs, and not directories. That means that if someone creates an alias to the document root, they'll completely bypass these authentication rules. (See http://httpd.apache.org/docs/2.0/mod/core.html#location for more.)

提交回复
热议问题