سؤال

I am developing an application that has to run both locally as well as on a remote server. One directory is protected using an htpasswd file. This how I have to define the path to the htpasswd file in the htaccess file:

AuthUserFile ../app/some-folder/.htpasswd

Unfortunately the app folder is required on the server, but I don't have that locally. Instead, the path has to look like this:

AuthUserFile /Volumes/some/very/long/path/some-folder/.htpasswd

Is it possible to us en if/else statement to switch this AuthUserFile path according to the current host (Edit: Or better yet, don't require any authentication locally)? Or is there another workaround to make this file work on both my local and the remote host?

هل كانت مفيدة؟

المحلول

Never mind, I figured it out. I put this in my .htaccess:

AuthName "Protected"
AuthType Basic
AuthUserFile path/to/.htpasswd
Require valid-user
Order deny,allow
Deny from all
Allow from 127.0.0.1
Satisfy Any

This allows any connections made from the local IP to go through without entering a password. Not perfect, but works in my situation.

نصائح أخرى

With Apache 2.4+ you can use the If directive with %{HTTP_HOST} in .htaccess.

<If "%{HTTP_HOST} == 'localhost'">
AuthUserFile /development-path/.htpasswd
</If>

<Else>
AuthUserFile /production-path/.htpasswd
</Else>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top