File .htaccess, a powerful tool that allows you to arrive further on in your webpage

that-be-file-htaccess

You need to make changes in the configuration of the archives your servant and you don't know by where beginning? It gives fear to change something You and to break it everything? Hopefully there would be some way to be able to make all that without the nuisance touch where you do not have and always being able to give return back, truth?

Then we have the good news for you. It exists, file is called .htaccess and in the today post we discovered all secrets to you: of what it consists, how it is created, examples than it can do, etc.

It interests to You to know something thus? Then you only must continue reading.

What is the file .htaccess?

Wikipedia defines it of the following way:

A file .htaccess (hypertext Access), also known as distributed configuration file, is a special file, popularized by Servant HTTP Apache who allows to define different directives from configuration for each directory (with its respective subdirectories) without needing publishing the main configuration file of Apache.

Or shelp with a more level language, one is a file that allows to alter the configuration you of the servant where your webpage is lodged. That of general form but, in particular, is used for:

All this without having “to touch” of direct form in the servant and without having to reinitiate it before each change.

How to create your own file .htaccess

Like it happens with the robots.txt file and sitemap.xml, to have your own .htaccess you only need any text editor and to know his syntax. But before putting hands to you to the work, you must know that:

  • If one in your servant already exists, the best thing is than you keep a backup copy “just in case”.
  • The file only affects to the folder in which it is and to that there is underneath, reason why its suitable place is the root directory.
  • A pad admits commentaries putting at the beginning of each phrase (#).

And finally (and more important) the file .htaccess uses format ASCII and it does not have extension. This it tenth because, if you use the notepad for example, when keeping it is necessary it to watch that it does not add at the end of the name “.txt”, since that will cause that it does not work.

In summary, the file that you raise hosting must be called “.htaccess” to droughts.

Examples of .htaccess, what you can do with this file?

All the theory that we have to you until now counted is very well, but you what you want are to see everything what the file .htaccess is able to do, truth? Neither one hundred thousand words the more… Your desires are orders. 😉

1. To change the error pages

No matter how much you follow the best advice of SEO than it has, if in your website there are pages that show an error, the finders penalize to you. For that reason it is so important that does not happen.

And to avoid them, at least the 404 that is most common, are enough with a single line in the file .htaccess:

ErrorDocument 404: “Ups! It seems that something has left badly…” or the text that you want in inverted commas.

Or if you prefer it, you can redirigir to a page that you have created exclusively for that with the following line:

ErrorDocument 403 /paginas/error403.html

If you pay attention, the code of the error is another one… It is to slug so that you see that it is enough with changing it in function to the error that you want to solve.

2. To block bots malignant

They are known as “bots” the programs that create the companies to track the webpages. Google has theirs like Bing, Yahoo and many more companies. Which is the problem? That some have put in circulation bots with intentions to attack blogs, stores online and all type of websites sobrecargárdando its servers.

If you have chosen well your company of hosting in principle you are safe but, as never it comes bad to add a protection extra, we see how one becomes from .htaccess:

RewriteEngine on

RewriteCond % \ {HTTP_REFERER} 7makemoneyonline \ .com [NC, OR]

RewriteCond % \ {HTTP_REFERER} burger-imperia \ .com [NC, OR]

In this example we have blocked two sites and, if you want to see a list of that you would have to block, you have it here.

3. To add password to a directory

In this other post we taught to you how to protect your WordPress of the hackers but, to part of those measures, to block the more important archives and folders with a key it is a good option.

Something that you can do with .htaccess (that in addition is used par excellence for the CMS or any other type of page) following these simple steps:

  1. It creates a file with the name .htpasswd where to write the codified user and password. For it, you can use this webpage.
  2. Once you have the file with the codified data, she raises the servant in a folder different from which you want to protect.
  3. In the directory that you want to protect, it creates .htaccess with the following code: Based “Directory” AuthName
    AuthUserFile /carpeta/.htpasswd
    AuthType BASIC
    Require to valid-user “Directory coding”

Now whenever somebody tries to enter, it only can do it if it meets the user and the password.

4. To force the HTTPS use

A time ago we especially saw the importance that has for your webpage the use of https, if is a store online. For that reason, if your business has a certificate SSL is vital that you force to everybody that it enters through him.

And to do it is as simple as to copy these 3 lines of code in your file .htaccess:

RewriteEngine On
RewriteCond % \ {HTTPS}! on
RewriteRule (. *) https://% \ {HTTP_HOST} % \ {REQUEST_URI}

That yes, to thus include something without having the most probable certificate SSL is than it prevents to accede to the page and it generates an error.

You know something more than the file .htaccess can do?

These are only some examples than .htaccess can be obtained thanks to the file, but it has much more. You know something more than it is possible to be done with him? You have implemented some of the examples that we have seen in the post?

Answer us those questions, or tell us what she desires to you, using the commentaries that there are right under these lines. And if it is going to be your first time, it would enchant to us that you returned and you told your experience us. 😉