阿帕奇:重写前基本身份验证 [英] apache: basic authentication before rewrite

查看:213
本文介绍了阿帕奇:重写前基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在前端一个Apache重定向通过重写规则的请求。
我以前把一个基本身份验证重定向的请求,所以我把这个配置文件:

I have an apache in frontend that redirect a request via a rewrite rule. I have to put a basic authentication before redirect a request, so I put this in the config file:

<VirtualHost *:443>
    ServerAdmin xxxxxx
    DocumentRoot /var/www/html/
    ServerName xxxxxxx
    RewriteEngine on
    ErrorLog logs/error.log
    CustomLog logs/access_log common

    <Directory /var/www/html/>
        AuthType Basic
        AuthName "Restricted Files"
        AuthUserFile /etc/httpd/conf/tag.pwd
        Require valid-user
        RewriteRule ^/(.*) http://xxxxxx:xxx/$1   [P,L]
    </Directory>
</VirtualHost>

但不起作用。

有什么建议?

推荐答案

我解决了把重写条件并重写Locatio指令之外的规则:

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

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

非常感谢h0tw1r3您的建议

many thanks to h0tw1r3 for the suggestion

*请记住,位置上的指示操作的URL,而不是目录。这意味着,如果某人创建一个别名文档根,他们会完全绕过这些认证规则。 (请参阅http://httpd.apache.org/docs/2.0/mod/core.html#location更多。)

*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.)

这篇关于阿帕奇:重写前基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆