What are .htaccess files and how to create and edit them

.htaccess files are used to configure and provide the server with instuctions regarding the processing and serving of your website. This is done by putting directives in an .htaccess file. You can do many things with .htaccess files; for example, you can protect files and folders, specify various rewriting and redirecting rules, improve the cache, compress the served content, etc. The Apache server is configured with some default settings, but by using .htaccess files you can provide additional settings or override some of the default ones. Of course, for security reasons there are some limits to the things that you can do with .htaccess.

You can put an .htaccess file in the public_html directory on your hosting account or in any subfolder within public_html. The directives that you put in an .htaccess file work recursively in all subfolders. This means that, for example, the directives in an .htaccess file that's in the pubic_html directory on your account will affect your whole site (the whole web-accessible content).

When you put directives in an .htaccess file, put each directive on a new line. You can also insert comments and comment out directives. You can do this with the hashtag sign (e.g. #). By putting the symbol at the beginning of a line it will be considered a comment. You can use this to put comments and explanations before directives so that you know what the particular directives are used for. If you don't want particular directives to be active anymore, instead of deleting them you can comment them out to make them inactive. In this way, if you want to use the directives at some point later, you can just remove the number sign.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

[WHM/cPanel] Changing Home directory

What is the document root? When you visit a website, you are accessing a particular folder on...

PDFinfo

Pdfinfo is a pretty useful tool.  Pdfinfo prints the contents of the 'Info' dictionary (plus some...

Installing GeoIP (PECL) on WHM

In order to install GeoIP via PECL on a WHM enabled server, you must first install 2 modules:1)...

[WHM/cPanel] CloudLinux PHP selector not saving on cPanel 54 and CL 6.x & 7.x

Problem:When trying to change php extensions in paper_lantern, nothing saves. I can click Save or...

Mon Compte a été Piraté

Un compte piraté (ou hacké) est un compte qui a été compromis par un individu non-autorisé....