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(s). 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 (going down as many levels as you want). 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).

One easy way to create and edit .htaccess files is from the Files section of the Pixie control panel. In the black area on the right there's a Create File button. Just click on it and on the following page type .htaccess (don't forget the dot) in the field for New File, and then click on the Create File button that's under the field. To edit a file through the file manager of the Pixie control panel just click on the name of the file.

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 number 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.

Was this answer helpful?

 Print this Article

Also Read