The document root for “https://www.example.com/” is “/web/”
Path secret is a virtual path which does not reflect to a real directory with name “secret” (e.g. an existing rewrite rule in .htaccess)
Now we want to protect file “file1.htm” directory “D” and directory “E”, “F” and virtual path “secret”
1.1 We need to create a .htaccess file under “web” directory
1.2 Open the .htaccess file, we need to add following contents for protecting files
#Password file path
#Message for user to see
AuthName "Password protected"
#(If only allow specific user, use "require user username" if allow all valid users use "Require valid-user")
require user username
Note: if dealing with multiple files, filesmatch should be used.
1.3 We add following content to protect directories and the virtual path (We can use this method to protect multiple sub-directories/sub-folders/paths)
#Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/ resource2\/B\/C\/D require_auth=true
SetEnvIf Request_URI ^/ resource3\/E require_auth=true
AuthName "Password protected"
#Setup a deny/allow
#Deny from everyone
Deny from all
#except if either of these are satisfied
#1. a valid authenticated user
#or 2. the "require_auth" var is NOT set
Allow from env=!require_auth
These password can be generated using htpasswd with following command:
$ sudo htpasswd -c /web/.htpasswd user1
(You will need to supply and confirm the password for the user)
$ sudo htpasswd /web/.htpasswd user2
Another way to protect current directory:
e.g. If we want to protect directory “A”
2.1 Creat a .htaccess file under in directory “A”, so we have “/web/resource1/A/.htaccess”
2.2 We add following content to the file
<Files ~ "^.(htaccess|htpasswd)$">
deny from all
AuthName "Please enter your ID and password"
2.3 We create the .htpasswd file under “/web/resource1/A/”, so we have “/web/resource1/A/.htpasswd”
2.4 We generate password as in step 1.5 (We need to change path from “/web/.htpasswd” to “/web/resource1/A/.htpasswd”)
Now the directory “A” is protected
1 We can use online .htpasswd generator to create password for convenience
The application encountered an error while attempting to change the state of ‘New Virtual Machine’.
‘New Virtual Machine’ failed to start.
Synthetic SCSI Controller (Instance ID xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx): Failed to Power on with Error ‘General access denied error’.
Hyper-V Virtual Machine Management service Account does not have permission to open attachment ‘D:\vm.vhdx’. Error ‘General access denied error’.
Note: Other similar errors which is related to virtual hard drive (vhd, vhdx) permission issue when starting the Hyper-V virtual might also be fix by using following method.
Remove the virtual hard drive from virtual machine via Hyper-V Manager then reattach the hard drive
1 We need to get the SID of the virtual machine, usually it will be displayed in the error dialogue. If you have the SID continue with step 2, If not, follow the steps below:
1.1 Open the Run window by using Win + R key combination.
1.2 Type virtmgmt.msc and hit “OK” button
1.3 Write down the name of the virtual machine which is having perimssion issue.
1.4 Use key combination Win + X, click on Windows PowerShell (Admin) to open PowerShell window. Type following command and hit Enter key (Replace Name of Virtual Machine to your virtual machine’s name)
Get-VM 'Name of Virtual Machine' | Select-Object VMID
2 Enter following command in PowerShell to grant permission for this virtual machine to attach the virtual herd drive. ()
icacls "<Path of .vhd or .avhd file>" /grant "NT VIRTUAL MACHINE\<Virtual Machine ID from step 1>":F
icacls "<Path of .vhd or .avhd file>" /grant "<Virtual Machine ID from step 1>":F
Tip: By default Hyper-V store virtual machine configuration files in “C:\ProgramData\Microsoft\Windows\Hyper-V”, hard drives in “C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks”
Warning: You must confirm that your computer supports UEFI mode, otherwise you will not be able to boot into the system after the conversion. It’s always good to do a backup before starting to convert.
1 Open an elevated command prompt (Win + X, Select “Command prompt (Admin)” or “Windows PowerShell (Admin)”)
2 Type following command and hit Enter key. (If the current MBR disk has four partitions, the following command will fail and return this error “Disk layout validation failed for disk 0”, you can try to delete one if not required and convert again)
mbr2gpt /convert /allowfullOS
3 Reboot, start into BIOS, change BIOS mode from legacy or CSM to UEFI (You might need to check which key to press to enter BIOS, different motherboard has different keys)
“*Something settings are hidden or managed by your organization.”
If you have encountered these messages, try following methods to fix it:
1 Use key combination Win + R to open then Run window
2 Type cmd.exe then hit Enterkey
3 Type or copy and paste following command to the command prompt window and hit Enter Key to run the command. (NOTE: If failed due to permission issue, Instead of Step 2, Use key combination Win + X, then Click on Command Prompt (Admin) or Windows Powershell (Admin), then continue from step 3)