What is .htaccess ?
.htaccess (hypertext access) is a useful file for Many of web server to apply settings per directory basis. It allows to override default configuration of Apache server on run time. Using .htaccess we can easily enable or disable any functionality at the run time.
.htaccess is a complete file name, It’s not just the extension of file.
Be careful while working with .htaccess configuration. Any small mistake may stop your entire site. Most probably we get 500 error with any syntax error in .htaccess file.
Uses of .htaccess ?
We can use .htaccess to accomplish various tasks at the run time. Below is a list of some most frequently uses of .htaccess.
1. Redirect or Rewrite URLs
Using .htaccess we can easily redirect user from one url to other url easily. Also we can direct urls to other url without changing url in browser windows.
2. Enable Password Protection
Using .htaccess we can enable basic http authentication on entire site or on a specific directory access. It prevent unauthorized access of data.
3. Define Custom Error Pages
When our website faces any error in backend, web server shows its pre defined error pages for each errors. We can redesign own error pages and show to end users in case of error occurred on site.
4. Allow or Deny Users
We can simply restrict any users to access entire site of specific pages of website based on there ip address. We can simple allow our secure pages to access from specific ips only. In that case if any user tried to access secure page from unauthorized pages will get error page.
5. Change URLs
.htaccess is widely used for changing website urls to make to simple and seo friendly. We can easily convert urls showing in web browser user-friendly.