Let’s first know the basics of HTACCESS.
What is .htaccess files
Firstly a .htaccess file is simply an instruction file which instructs server how an WEB-ADMIN wants to give access to a directory of file. In Cpanel we can easily do this from interface . What cpanel actually does is it simply edits the htaccess file. Htaccess file can be used for the following functions rewriting URLs, prohibiting hotlinks, reconfiguring account settings, creating redirects, and much more. Changing this htaccess file will simply change the configuration of your whole site. So you must take a backup first for an online site. For our case, we simply want to create a .htaccess file on our localhost. So let’s jump into the process:
How to Enable .htaccess on WAMP / XAMPP / MAMP for testing in localhost
First Run your WAMP or XAMPP or MAMP. I will be showing you using WAMP on a Windows PC. You can configure XAMPP/MAMP with the similar settings. Now click on the WAMP icon which you will see on the System Tray . You will see something like this: Now hover over the Apache settings and click on the httpd.conf.
This is the configuration file which we need to edit. So you have opened the file in notepad,right? alright. Now please scroll down until you find this line Remove the Hash sign from the beginning of this line so it looks like this: Now Save the file. Congratulations! You have just enabled htaccess on WAMP and you are now ready to unleash the power of htaccess even from localhost.
How to create a .htaccess file on Windows PC?
Now the most important part. First you have to decide which folder of your site you want to manage using htaccess file? Because you have to create .htaccess file on that folder. Suppose you have a folder in C:\wamp\www\jobs\admin and you want to revoke access of this folder for everyone. So you have to create the .htaccess file on admin folder . First open the folder for which you want to control the acceess and create a text file and name it as ABC.htaccess . Now open this file ABC.htaccess using Notepad and write the .htaccess code here.For this case I want to revoke direct access to admin folder so I put something like this “deny from all” in the ABC.htaccess file. Remember there is ABC before .htaccess . Now you may ask me why? As you might already know that we can not simple create .htaccess file in windows computer because it thinks this a file without any name and it’s format is htaccess. Now the fun part.
How to rename ABC.htaccess to .htaccess
This is super easy. We can use Command Prompt to do that.
First click WINDOWS KEY+R and Run window appears Now write CMD in the command prompt write this:
In this command ren means rename . This command will rename ABC.htaccess to .htaccess. VOILA! You have successfully created a .htaccess file on your computer.