What is the Use of .htaccess File in Our Website ? Where it is Located ?

.htaccess is a plain text file. The file name comes from hypertext access, a configuration file supported by a number of web servers and used to control server settings in a decentralized way. It is placed within the file tree and is capable of overriding the secondary server settings of the folder in it and its contents of files and subfolders. And the .htaccess file is one of the most important files on which the Web sites rely on the Apache HTTP Server servers.You can easily create a htaccess file from a plain text editor that opens the editor and then saves the file under the .htaccess name

.htaccess

Today our topic is very important for web developers about the htaccess file, often you find it inside a script folder or hosting site, but have you ever wonder what the purpose of this file is ?

What is the Use of .htaccess File in Our Website ? Where it is Located ?


What is the htaccess file?

.htaccess is a plain text file. The file name comes from hypertext access, a configuration file supported by a number of web servers and used to control server settings in a decentralized way. It is placed within the file tree and is capable of overriding the secondary server settings of the folder in it and its contents of files and subfolders. And the .htaccess file is one of the most important files on which the Web sites rely on the Apache HTTP Server servers.

How do I create an .htaccess file. ?

You can easily create a htaccess file from a plain text editor that opens the editor and then saves the file under the .htaccess name

 If you are a Windows user which will prevent you from creating the file, the solution is to save the file under the name of htaccess.txt. When you upload it to your host, rename it to "htaccess." It is recommended that you create it in the main folder to host you directly.

What are its uses?


  • Protect the site folders with a user name and password.
  • Redirect from one page to another.
  • Clean links by RewriteRule.
  • Define the host server with SSI commands that you design for your site
  • Protect the bandwidth in the site from external consumption both in files and images.
  • Block the site from visitors from a particular country or make it to visitors of a particular country or block it from a specific IP.
  • Hide folder contents for members or a specific type of file only in the folder.
  • Make error pages.
And other important uses of the site ...

Some commands are htaccess file. ?

1. Set the index file to the main index of the site:

DirectoryIndex main.php

2. Change the original name of your pages:


RewriteEngine on
RewriteRule ^ new-page.html $ page.php

3. Prevent a specific IP from accessing your site:

denied from 000,000,000,000
Change the 000,000,000,000 to the ip you want to prevent from accessing your site.

4. Set error pages:

ErrorDocument 401 /err/401.php
ErrorDocument 403 /err/403.php
ErrorDocument 404 /err/404.php
ErrorDocument 500 /err/500.php


5. Redirecting HTaccess 301:

RewriteEngine On
Redirect 301 / old-webpage http://www.yourblog.com/new-webpage

6. Set charset to htaccess:

AddCharset UTF-8 .html

Do not forget to share your opinion in the comments section and also join us on the social networking sites to stay connected with us.

About the Author

I am Avnish Kumar owner of this blog. I like to write tech article. As being a student, managing this site, writing tech articles it is little bit difficult as there is no enough time.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.