Code Snippet
Allow Single URL Through .htaccess Password Protection
This code is useful for multi environment setups (staging, production, etc.) it allows you to keep your htaccess files in sync while maintaining an htpasswd on your development environment or anything but the live environment.
#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
I found your .htaccess setup to be pretty good, but I found it more useful to allow from all then deny from staging.
Below is the reverse of what your have in this article.
Keep up the great work!
#-- Staging Server Password -------------------------#
SetEnvIf Host yourstagingserver.com passreq
AuthType Basic
AuthName "Staging Server"
AuthUserFile /home/username/.htpasswd
AuthGroupFile /home/username/.htgroup
Require valid-user
Order allow,deny
Allow from all
Deny from env=passreq
Satisfy any
Hi,
I am trying to do something similar, thought I’m not sure if it’s possible. I have an images directory on my server and I would like the images to be accessed only by one of my php pages, preventing hotlinking and direct access. For instance:
Directory:
http://www.mysite.com/images/
containing the files: 001.jpg / 002.jpg / etc
Page:
http://www.mysite.com/images.php?file=001
to view file 001.jpg
Any ideas of how should I configure my htaccess file?
PS: I don’t know if it’s important since you are using REQUEST_URI, but I have multiple domains on my server (ex. http://www.mysite.com and http://www.mysite.net)
Yep, thats exactly what I am searching for since sunday. hotlinking from one server only to only one single url.
@BRAULIO did you find a solution ??
May try if these suggestions works for you George
About midway through the page is a section about hotlinking images.
http://www.gwizit.com/articles/getout.php
Seemed to help my site from getting hotlinked any further.