Mã này hữu ích cho các thiết lập đa môi trường (dàn dựng, sản xuất, v.v.), nó cho phép bạn giữ các tệp htaccess của mình được đồng bộ hóa trong khi duy trì một htpasswd trên môi trường phát triển của bạn hoặc bất kỳ thứ gì ngoại trừ môi trường sống.
#allows a single uri through the .htaccess password protection SetEnvIf Request_URI "/testing_uri$" test_uri #allows everything if its on a certain host SetEnvIf HOST "^testing.yoursite.com" testing_url SetEnvIf HOST "^yoursite.com" live_url Order Deny,Allow AuthName "Restricted Area" AuthType Basic AuthUserFile /path/to/your/.htpasswd AuthGroupFile / Require valid-user #Allow valid-user Deny from all Allow from env=test_uri Allow from env=testing_url Allow from env=live_url Satisfy any