What Is .htaccess?

.htaccess is used on Apache web servers as a way to define rules, modify configurations, and enable or disable additional functionalities of the server. For example, .htaccess can be used to set error pages (Like 404 - Not Found). .htaccess is quite powerful, and it is definitely an amazing tool on the Apache server.

What can .htaccess do?

There are many things that .htaccess can accomplish. For example, you can set error pages, password protection, geological and IP-related restrictions, as well as controlling the URL and page redirection on your website. An important thing to remember is that .htaccess is the full filename, nothing comes before the dot. This may cause it to be hidden by some filesystems, so make sure you allow hidden files if you need to!

Advertisement

What does .htaccess look like?

Here is an example of .htaccess file:

.htaccess File Example


RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] RewriteRule ^ %1 [R,L,NC]

Looks like a mess right! Don’t worry, you don’t have to understand it yet (And hopefully I didn't scare you)! The example above modifies the URL of a webpage, and removes the .html and .php extensions if they are present.

How do I get started?

If you want to learn how to write htaccess statments yourself, there are many online resources out there to help you out. Thankfully, you will almost never have to create your own statments, as there are many websites that provide them for you, including ours! We have an entire list of things you can do with htaccess, and they can all be found in the .htaccess topic listing!

Advertisement

Conclusion

Short but sweet. You learned what .htaccess is, as well as what it can do. Why are you still reading this this guide? You could be getting started creating your own files already!

Advertisement

Article by Tinkerman