Jump to content

[SOLVED] IF Statements in .htaccess


rhodesa

Recommended Posts

Heys guys, as a developer I'll usually have a local copy of a site I'm working on and then the copy that is in production. Since the environments are different, sometimes they need to be slightly different (paths usually). I'm all set on doing conditionals in the PHP code of the site, but I can't figure out how to do conditionals for Apache Configs. For instance, if I am using HTTP Basic Auth, on my local system the line might look like:

AuthUserFile /usr/local/apache/passwd/passwords

while on my production server it might be:

AuthUserFile /home/useracct/hostname.com/passwords

Is there a way to test the HOST or SERVER name to determine which line to use dynamically?

Link to comment
https://forums.phpfreaks.com/topic/145074-solved-if-statements-in-htaccess/
Share on other sites

well...just to let everyone know...

 

i couldn't find anything designed for it, but i was able to work around it by using <IfModule>. i compared the list of loaded modules between the two servers and found a module that was on one but not the other. then, i used this:

AuthType Basic
AuthName "Protected"
Require valid-user

<IfModule prefork.c>
#Mini
AuthUserFile /www/websites/foobar/admin/.htpasswd
</IfModule>
<IfModule !prefork.c>
#arhodes
AuthUserFile "C:\webserver\eclipse_ws\foobar\admin\.htpasswd"
</IfModule>

 

not what it was designed for...but it works :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.