WordPress creation of a .htaccess file – Learn how to create a .htaccess file

An .htaccess file is a configuration file that an Apache server, i.e. a program, can reconfigure indirectly. To change the “behavior” of the selected web server (httpd.conf), the user does not need to have direct access to the main configuration file.

It is particularly important to note that the .htaccess instructions always refer to the directory in which the file is located. This file should always be located in the root directory so that the settings have a global effect. Even if this all seems very theoretical and technical at first, it is still advisable to look into the subject. Using special codes for the .htaccess, the CMS (Content Management System) WordPress can be made even faster and more secure.

What is the .htaccess file and what can you do with it?

Htaccess is an abbreviation and stands for Hypertext Access (Hypertext Access). The .htaccess file is a server configuration file that can be used to influence the configuration of the Apache web server. Access to the main configuration file (httpd.conf) is not required for this. A configuring text file defines the initial settings with which a program or server should work. The file is responsible for ensuring that the server on which the WordPress installation, follows certain rights of action. The .htaccess file offers the advantage that it is read with every server request and not only after a restart. As a result, the changes in the WordPress .htaccess are implemented immediately.

Such a file tells the server how individual processes on your website should be handled. You can use the .htaccess…

  • … own HTTP error messages can be determined.
  • … Access for certain IP addresses, ranges or host names can be blocked by the wp-admin.
  • … own redirects can be set up.
  • … users are redirected.
  • … or even create access protection for files or an entire directory.

The .htaccess file is not written in a conventional programming language, but in the directive syntax. A line of text or code is always part of each command. Of course, this syntax must be understood by the server. All NCSA-compatible servers do this, e.g. Apache.

This file is a hidden file. This can be recognized by the dot in front of the htaccess. The file can therefore only be seen if your own FTP client is forced to display the hidden files. But even then, there are still individual cases in which the FTP client does not display the .htaccess.

Let us advise you free of charge:

Where is the WordPress .htaccess file located?

With WordPress, the .htaccess can be found in the main directory where the domain is hosted by the web host. This main directory is called the root directory. Using an FTP program (file transfer protocol), such as FileZilla, the user can access the directory and therefore the .htaccess file.

How do I get access to an .htaccess file and create it manually?

At the latest when the permalink settings are changed WordPress has a .htaccess file. In most cases, a change in these settings can resolve the lack of an .htaccess file. However, it is also possible that the automated creation of files is not possible. This then varies depending on the server configuration. When saving new permalink settings WordPress finally informs the user that no .htaccess file can be created. If this is the case, the following steps should be taken to create the file manually:

  1. First, the text editor must be opened and the document given any name, e.g. .htaccess file 1. No empty files can be created with an editor. It is particularly important to ensure that Microsoft Word or similar is not used, as these programs automatically enter additional formatting.
  2. The file is then uploaded to the server. To do this, the empty .htaccess must be uploaded to the main directory. This is done via FTP. The wp – config .php is also located in this folder.
  3. The .htaccess file is then renamed. The name previously selected as an example for the file must be renamed to “.htaccess” (without quotation marks).
  4. Finally, the rights to the file are assigned as required. WordPress must be able to fill the file with codes independently, as the .htaccess is ultimately empty. Some plugins require .htaccess write permissions for this. The file attributes must be adjusted for these rights. To make this setting, right-click on the .htaccess file in the FTP program and select the menu item “File permissions”. Writing to the .htaccess can now be permitted.

Important: No changes should be made without a backup!

Before making changes to the .htaccess in WordPress, it is essential to create a .htaccess backup and save the file. If something “breaks” in the new file, the original file can be easily activated or re-uploaded without having to undo all the changes. By renaming the current.htaccess and creating a new one, the backup can be carried out very easily.

“The file .htaccess does not exist in wp-admin.”

What needs to be done now and which plugin helps to continue using the .htaccess file?

The security analyses of the WordPress system in which the plugin is installed are carried out by WP Security. As soon as this analysis is carried out, a scan shows the existing gaps and gateways.

The user, i.e. the viewer of the front-end page, sees none of this and it is not “runtime-critical”. This means that the WP Security plugin and its outputs are only visible to administrators in the dashboard menu. As long as the scan is not executed, no computing time is consumed. Such a scan only takes a few seconds on average.

The disadvantage of the security plugin is that it is difficult to understand and is usually only used by experts and experienced server administrators. Operators who do not belong to the expert category are not particularly involved with the server and have problems rectifying the reported defects. This is therefore a so-called usability problem.

It would have been very helpful for some users if the authors had written some tips on the output after programming the security checks. On Google, the search query “wp security scan .htaccess” returns over 100,000 results, which clearly indicates a usability problem. On the other hand, you must also bear in mind that this tool is free of charge.

What needs to be done if the WordPress .htaccess file is deleted?

If this is the case and the file was accidentally deleted, the following code can be entered to resolve the problem:

Useful codes for the .htaccess file

There are some codes that can be used in addition to the standard lines of code in the .htaccess file. These codes are not a must, but they are very helpful. The additional codes can improve both performance and security. However, if too many codes are used, this can also have a retroactive effect and the performance is weakened. Particular attention should therefore be paid to which codes are really necessary and which are not. The following codes can also be used:

The optimal WordPress .htaccess file

New codes can be added to the .htaccess WordPress and too much code has exactly the opposite effect. This effect is comparable to extensions such as caching plugins or similar, which partly work via lines of code in the .htaccess. It is therefore important to find out which combination of codes/plugins represents the optimum case in terms of security and performance.

A perfect .htaccess file for WordPress, which does not contain any superfluous lines or ballast, could look like this, for example. It is particularly important that all really important commands and points are retained. As a result, the file is slim, small and, above all, extremely fast. Starting with compressing the pages with Gzip, which can reduce the size per page by up to 80% and, for example, can be used to create a new version. prohibits the linking of images on third-party websites. This is done via the ultimate WordPress .htaccess cached graphics and thus ensures excellent performance. To do this, the existing code in the standard .htaccess must be replaced with the following. ->

When optimizing the WordPress .htaccess, the following instructions should be observed:

  1. A code appears in the WP htaccess in which a URL must be entered. For example, “fastwp” was entered for the URL in the figure above. This name must of course be replaced by your own URL for the code to work.
  2. The code may need to be extended if there are web fonts on your own server.

WP Rocket

WP Rocket is one of the best caching plugins for WordPress. It is very easy to use and helps to compress the website and make it faster. There are several caching plugins for WordPress, but WP Rocket is one of the best. This is not only because it is the fastest plugin, but also because it is the easiest to use. This plugin is not free, but compared to other paid plugins it offers many new features.

Get free advice now

Our team will be happy to help you

Melanie Fantastico


Alexander Zimpel

SEO consultant

Related posts