Aug 27, 2012 | Apache Server, htaccess
You are developing a new site and wish to keep it secret till your new site is ready for launch? You got personal photos, confidential documents, project codes uploaded to your web server for future reference or download and you want to give access only to certain people? One of the solutions is to password protect your directory where the restricted stuffs were stored. “How to password protect the directory or entire website?” Requirements: – Hosted on apache server – Apache module mod_access is enabled. Step 1 Create password file “.htpasswd”. In the folder / site root you wish to password protect, create a .htpasswd file. The password file stores your valid users’ username and password. Step 2 Use online passwd generator to create user’s username and password entry for htpasswd. http://www.htaccesstools.com/htpasswd-generator/ Copy and paste the entries into “.htpasswd”. Example of an .htpasswd file denny:$apr1$7APPNnCz$M./pcs91u296uBP0VAD4J1 Step 3 In the same folder, create/edit .htaccess to include the following codes. AuthUserFile /absolute/path/to/.htpasswd AuthType Basic AuthName "Prompt Title" Require valid-user Note: Relative path to .htpasswd will not work. Final Step Launch your browser, navigate to the password protected folder, you will receive a authentication challenge if nothing goes wrong. =D That’s...
Oct 23, 2010 | Apache Server, htaccess
One common approach of code migration. Redirect normal users to maintenance page while migration testers carry out production testing after completion. The solution – amend our .htaccess file to redirect all incoming request to maintenance except for request from testers’ office IP address. #.htaccess RewriteEngine on #Check if request is not server_down_message.html and ip is not from testers' ip address #Change xxx.xxx.xxx.xxx to your ip address, eg. 202.126.4.10 RewriteCond %{REQUEST_URI} !/server_down_message.html$ RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx #To allow more IP addresses, simply append "RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx" under this line #Both conditional are true #Not requesting for server_down_message.html and IP address not from tester. #Redirect to server_down_message.html RewriteRule $ /server_down_message.html [R=302,L] Hope it helps you and good luck with your...