How to use a RELATIVE path with AuthUserFile in htaccess?

后端 未结 9 1376
我在风中等你
我在风中等你 2021-01-31 12:51

I have a .htaccess that uses basic authentication. It seems the path to the .htpasswd file isn\'t relative to the htaccess file, but instead to the server config.

So eve

9条回答
  •  迷失自我
    2021-01-31 13:26

    It is not possible to use relative paths for AuthUserFile:

    File-path is the path to the user file. If it is not absolute (i.e., if it doesn't begin with a slash), it is treated as relative to the ServerRoot.

    You have to accept and work around that limitation.


    We're using IfDefine together with an apache2 command line parameter:

    .htaccess (suitable for both development and live systems):

    
      AuthType Basic
      AuthName "Say the secret word"
      AuthUserFile /var/www/hostname/.htpasswd
      Require valid-user
    
    

    Development server configuration (Debian)

    Append the following to /etc/apache2/envvars:

    export APACHE_ARGUMENTS=-Ddevelopment
    

    Restart your apache afterwards and you'll get a password prompt only when you're not on the development server.

    You can of course add another IfDefine for the development server, just copy the block and remove the !.

提交回复
热议问题