Intro

The Apache server (also known as the httpd service) is the one responsible of serving and handling all requests as responses from our website. If our web hosting runs with Apache, the server receives a URL and process it returning the entire content shown on our browsers, so every set of data we send to, or receive from the web server passes through this service.

Most Linux based servers run with Apache.

What an .htaccess file is and what it does

Apache has the feature to process a file named .htaccess which is a configuration file where we can set rules to be executed before any request to the server gets processed. And there can be an .htaccess file under each directory, having its own set of rules for that folder/directory.

Some of the rules an .htaccess file can have are, for example:

  • Basic and advanced redirects
  • Password protected content
  • Hotlink prevention (blocking other sites to load your media and consuming your hosting bandwith)
  • Deny access by IP
  • Blocking bots
  • Deny directory listing
  • Handling friendly / pretty URL’s (making URL’s more readable for humans and search engines)
  • etc.

Notes and resources

  • The .htaccess file uses hierarchy, so the rules inside it apply to all directories and folders inside it.
  • A simple syntax error in this file can prevent an entire website to work.
  • This file has no name, it’s basically just an extension after the period. Windows based systems can throw an error when trying to create this file from zero.

To know more about .htaccess files you can check this resources: