Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to force https and basic auth for server-status output (mod_status). If I enable auth and user asks for http://site/server-status apache first asks for pass, then redirects to httpS, then asks for pass again.

This question is similar to Apache - Redirect to https before AUTH and force https with apache before .htpasswd but I cannot get it work because we are speaking not about generic folder but Location structure.

My config (shortly) is as follows:

<Location /server-status>
    SSLRequireSSL
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /server-status
        RewriteCond %{HTTPS} off
                RewriteCond %{SERVER_PORT} 80
                RewriteRule ^ - [E=nossl]
                RewriteRule (.*) https://site/server-status} [R=301,L]
    </IfModule>

    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost ip6-localhost
    Allow from 1.2.3.0/24

    Allow from env=nossl

    AuthUserFile /etc/httpd/status-htpasswd
    AuthName "Password protected"
    AuthType Basic
    Require valid-user

    Satisfy any
</Location>

I assume Allow from env=nossl should allow everyone with RewriteCond %{HTTPS} off and server port 80, then force it to redirect but it does not work.

Please note, I do not want force to SSL the whole site but /server-status only. If it matters the server has several sites.

What am I doing wrong? Thank you.

share|improve this question
add comment

1 Answer

I didn't have much luck getting RewriteCond %{HTTPS} off working - instead, what worked for me was

RewriteCond    %{SERVER_PORT}   !443

Another suggestion (from this question) would be to move the Auth lines into a <VirtualHost *:443> section.

share|improve this answer
    
Have just tested: doesn't work. It asks for pass before redirect. –  Putnik Nov 28 '12 at 16:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.