How do you know that the server is sending a 404 warning? Features and secrets of correctly setting up the .htaccess file

Storinka 404- this is the side that opens when police 404. Pomilka 404- Let’s try to open the unknown side. So, if you enter the wrong address (or follow instructions that don’t work), then you will immediately go to the wrong side. Of course, the browser itself has a built-in side. Well, I think that you would like to design this side differently, perhaps write some of your text and so on. About those how to install side 404 to your website, I will let you know.

First thing you need to earn - this create the .htaccess file. Please note that there is no file name and extension " htaccess". How do you work in Unix, then the problems are not the fault of the creatures. And the axis you work with Windows, then create the file .htaccess it’s possible like this (this is how I say it, although perhaps there are more simple ways):

  1. Open notepad.
  2. Vibrate menu item Save the yak".
  3. Enter file name " .htaccess".
  4. Select file type " All files".
  5. Save.

As a result, you will have a file .htaccess. Copy it to the root of your website. Now you can open it (for example, in the same notepad) and write the following line there:

ErrorDocument 404 /404.html

Now create a side “404.html” at the root of the site, in whichever you write HTML code, for example, like this:





The side doesn’t sleep!


Please check if the address you entered is correct.


With respect, My site



In this way, people will view not the standard page in the browser, but the page that V created.

Finally, I would like to say one important thing. If you are working on a local computer, then a server (for example, a package) can be installed on the new computer. Denwer, before what time to enter i Apache server, і PHP, і MySQL And a lot more).

Page 404 is clicked to inform customers that the url (page address) is not working.
Such incorrect URLs can also be called “broken URLs”.
There are a lot of sites that want to build their 404 pages to ensure the safety of their customers. Often these are beautiful and useful pages, which make the customer laugh instead of disappointment because the address of the page is incorrect.
When opening the page 404, the technical storage is important, which greatly affects the ranking of sites in search engines, since everything is not adjusted correctly.

If you were interested in the page 404, then you need to make three points:
1) Redirection of all incorrectly entered URLs to the 404 page in .htaccess.
2) Correct response from the server after redirection (the http code of the page may be 404, not 200).
3) Close the 404 page for indexing in robots.txt

Let me immediately note that everything is primarily written for self-written sites, most importantly in PHP. For WordPress there are plugins from the same setup. But in this statistic we will look at how everything looks true. %)

Redirection (redirect) of incorrect URLs to the page 404

First of all, what are you doing - creating the page 404 itself, so that you can get people to pay %).
URL redirection is configured in the .htaccess file
Just enter the row:
ErrorDocument 404 http://mysite.com/404.php
Where “mysite.com” is your domain, and http://mysite.com/404.php is the route to the real site. If your site is in html, then the row will look like this:
ErrorDocument 404 http://mysite.com/404.html
The conversion is very simple. After uploading the .htaccess file with the indicated row to the hosting, check it by entering the URL (the sent bit), which obviously does not work, for example: http://mysite.com/$%$%
As soon as the redirection to the page you created is successful, then everything works.
So, I’ll add the .htaccess file, where ONLY redirects on 404 are configured like this:
____________________________
RewriteEngine on
ErrorDocument 404 http://mysite.com/404.html
____________________________

The server's message is correct (http code for the page)

It is very important that when redirecting you receive the correct response from the server, and not 404 Not Found.
Let me explain this clearly here.

When entering any URL, a status (http-page) is assigned.
For all other pages: HTTP/1.1 200 OK
For redirect pages: HTTP/1.1 302 Found
As the pages are not clear, there are HTTP/1.1 404 Not Found

If any URL has not been entered, you will be given a status and a new server connection code.
You can check the server's confirmation on such a resource as bertal.ru or SEARCH CONCOLE GOOGLE – Scan/Scan as a GOOGLE bot.
If you were not redirected via .htaccess to the 404 page, then to some unknown URL, you entered it, and also on the sent bit there was a message “HTTP/1.1 404 Not Found”

After you have set up a redirect to your author's page 404 via .htaccess, as described above, then entering the message bit (invalid url, which is not clear), such as http://mysite.com/$%$% , the server's response will be :
- initially HTTP/1.1 302 Found (redirected),
- and then HTTP/1.1 200 OK (back page).

Check through bertal.ru.
Why am I threatening? This means that Google in its database (index) can enter all the bits of the message, like the original pages, instead of the page 404. In essence, duplicate pages. But this is extremely poor for sound optimization.

In this case it is necessary to make two speeches:
1) Set up the correct server response on the 404 page.
2) Close the 404 indexed page. Do it through the robots.txt file

We are adjusting the HTTP/1.1 404 Not Found server response for unknown pages

The server response is configured using the same php functions on the very front page:

Write a 404 file right away.
As a result, we can cancel the response on the sent bit:

Close the 404 page for indexing

You can close the indexing page in the file rodots.txt. Be respectful of this tool, and even through this file, your site is essentially linked to search robots!
The final text of the rodots.txt file, where the 404 page is closed by indexation, looks like this:
____________________________
User-agent: *
Disallow:
Disallow: /404.php
____________________________

Notes about the code: "/404.php" means sideways. If on your site the page 404.php (or 404.html is obviously) is in any folder, then you can see:
/holder/404.php
where "holder" is the name of the folder.

Axis, power and everything on the page 404. Turn over the work of the page, redirecting broken messages and types of servers.
I repeat: Everything is posted for self-written sites. If you are a WordPress vikor, you can look for a decent plugin for setting up 404 issues.

The .htaccess file gives you the ability to easily handle the Apache web server and set up settings in relation to the directory and folders that are installed on the server.

The success of the development and success of an Internet project largely depends on the correct and adequate operation of the server on which the site is being developed. Most of the time, Apache is a winner - mainly through the ease of setup and the great number of possibilities that are hoped for. You can configure this robot using both the main configuration file and the additional .htaccess file. Rotated on the server in separate folders, they indicate that they are the activities in this catalogue.

Correctly setting up htaccess makes it possible to directly adjust redirects on the site, register internal URL changes, add password authorization, etc. Let's talk about how you can earn money later.

How to properly configure .htaccess and everything else you need

Owners of sites that rely on virtual hosting services most often do not have access to httpd.conf. Therefore, the only way to manage the server for them will be to configure the htaccess file.
In essence and behind the structure, this is what httpd.conf suggests. On one note: the directives written in htaccess affect the directory in which the entire file is being expanded. And also folders and files. Otherwise, the actions will be the same as the directives to the global configuration file. So, for each directory, you can enter a separate .htaccess file with the necessary adjustments, without changing the global adjustments of the server and without having to contact the hoster for help.

Rule: first you start setting up htaccess, you must make a copy of the working file. This will help to update the data, as it is not possible. Incorrect changes will make the site inaccessible to hackers and search robots. It is therefore important to keep a current backup copy of the configuration file.

In addition to the directives specified in the configuration file, the user or Vlasnik website will be able to customize:

  1. PHP option.
  2. Keshuvannya.
  3. Redirective.
  4. Processing pardons 404.
  5. Redirect to https
  6. Access control etc.

The correct htaccess file will significantly simplify and optimize the work with the site, allowing you to connect to the view generated by the server.

We write htaccess correctly

The syntax of configuration file directives is simple.
When writing a pair of commands, their options are necessarily separated by a pass:

Command parameter1 parameter2 prapori

With the help of commands you can check the structure contributions, necessary activations and check the availability of certain modules.

Please note that failure to correct the syntax can lead to server failure. Correct htaccess is guilty of buti spellings like this:

  • The path to the file or directory is indicated at the server root:
    /home/mdhscyhq/public_html/
  • The domain is registered according to the assigned protocol:
    Redirect / https://yoursupersite.ru
  • The file name may include a “dot”:
    .htaccess
  • The file must be written in UNIX format.

The path to the root can be asked by the server administrator or you can see it yourself. To do this, just run the PHP-phpinfo function on the site and look at the doc_root values.

1.CNC adjustment

CNC, or a human-wise URL, positively (even if only a little) contributes to the relevance of the page to the site in the eyes of a search robot. Well, it advances the position according to the search. And also handy for a sailor when navigating.

Equalize:
http://yoursupersite.ru/index.html?id=4
і
http://yoursupersite.ru/razrabotka-sayta/

In the end, it becomes clear which side we are on and which information can be retrieved.
At the CNC you can enter keywords or phrases: Cyrillic or transliterated.
For example, from the standard url:
tovar.html?id=101
To help you change the CNC setup in htaccess, you can create a completely sensible url:
tovar-101.html.

RewriteRule ^tovar-(+)\.html$ tovar.html?id=$10

Or create a tree-like url structure: category/product-123.html

RewriteRule ^category/(+)/(+)\.html$ tovar.html?id=$20

2. Setting up PHP authorities

Change your hoster to block access to php.ini, otherwise you need to change the PHP settings, which can be done using an additional htaccess file.
Butt:

php_value post_max_size 10M php_value upload_max_filesize 32M php_value max_execution_time 200 php_value default_charset utf-8

Directives:
upload_max_filesize allows you to upload files up to 32 MB in size (up to 16 MB in case of restrictions).
post_max_size increases the posting size to 10MB (standard – 2MB).
max_execution_time allows the execution of complex scripts that require more than 30 standard seconds to complete.

3.Keshuvannya tributes

The htaccess file can be configured to cache, but it is not possible to use additional PHP syntax. In this case, to quickly collect data from the server, you can install the following modules:

  • mod_headers - allows you to insert different caching rules for files of different types into the server header.
  • mod_expires - refers to the term "old" files, the hour after each file will be placed in the browser cache.

With such sensor modules, different syntax may be required. Vikoristaniya of any kind is allowed (the choice is due to the installation on the server).

4. Setting up a redirect in htaccess

Customizing the htaccess file allows for simple and complex URL redirection. Then you can redirect the customer to another address globally:

Redirect / http://www.yoursupersite.ru

or when searching for other pages on the site:

Redirect / blog http://yoursupersite.ru/blog

The correct redirect for htaccess is the following syntax:

Redirect url_local url_redirect

There are a number of awkward rules that must be followed when setting up redirection via htaccess:

  • Redirections of pages in a file need to be expanded from private (in the middle of the page) to global. It's like a beast from bottom to bottom.
  • It is necessary to unique two or more recent redirects, because Most of the time, the feedback is negatively assessed by search robots.

How to correctly set up a 301 redirect in htaccess

When moving a site to a new domain or changing the CMS, there is a need to redirect users from old URLs to new addresses. A redirect with notification number 301 (Permament Redirect) informs the robot that documents and pages are being moved on a permanent basis. This allows you to save the site’s position in search engines, save your mileage and PageRank.
Setting up a 301 htaccess redirect can be done in a variety of ways, depending on the previously installed software and the goals set.
The simplest option:

Redirect 301 /new-1/ http://yoursupersite.ru/new-2/

Another method is that it is necessary to carefully redirect all addresses that are subject to redirection. Therefore, for complex redirects, it is better to use the mod_rewrite module, which allows you to select any type of URL rewrite and thereby adjust the level of rewrite from low minds and factors.
So, for example, you can change the redirection of pages whose URLs end with a slash to pages without a slash:

RewriteCond %(REQUEST_URI)!\? RewriteCond %(REQUEST_URI) !\& RewriteCond %(REQUEST_URI) !\= RewriteCond %(REQUEST_URI) !\. RewriteCond %(REQUEST_URI) ![^\/]$ RewriteRule ^(.*)\/$ /$1

And so, the page of the old domain is redirected to the page with a similar url on the new domain:

RewriteCond %(REQUEST_URI) (.*) RewriteRule ^(.*)$ http://site.ru/$1

5. Setting up 404 pardons in htaccess

Did you see that you moved the page from the site? Koristuvach, having passed the message in the search system or entering the wrong URL, send a notification about the payment 404. And, after everything, close the tab.
If this does not happen, the correct thing to do would be to carefully adjust the 404 redirect in htaccess and redirect the user to the main page of the site:

ErrorDocument 404 http://www.yoursupersite.ru/

However, this decision never came true. Marketers recommend creating a separate Not Found page, which will result in increased conversion. You can read the report on the design of the page “Pomilka 404”. And you can redirect the user to it using htaccess:

ErrorDocument 404http://www.yoursupersite.ru/404.html

In the same way, you can customize the display of notifications about amends:

ErrorDocument 401 http://www.yoursupersite.ru/401.html ErrorDocument 403 http://www.yoursupersite.ru/403.html ErrorDocument 500 http://www.yoursupersite.ru/500.html

6. Setting up a redirect to https in htaccess

The use of a secure SSL certificate and the https protocol will ensure secure communication and will be highly valued by search engines when ranking. To redirect all users of the site to this protocol and thereby ensure the reliability of data transfer, it is enough to add the following settings to the htaccess file:

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

7. Access control

In the htaccess file, with the help of special directives, you can restrict access to files and folders that are located in the stream directory:

deny from all

Vlasnik or the site administrator can allow access to clients from a specific IP address. It goes like this

order deny,allow deny from all allow from 192.168.ХХ.Х

If necessary, you can block or restrict access to files and folders to the directory via IP. This is followed by an additional offensive directive:

deny from 192.168.ХХ.Х

Replacement

Correctly setting up htaccess will ensure the correct functioning of the site. However, you should not forget about those that only have an additional configuration file; if possible, you will have to sacrifice httpd.conf. It also allows you to make more detailed adjustments to multiple folders on the server.

Today I will tell you about a bunch of cool speeches that can be made with the htaccess file. These are the words that you can use on your websites and work with websites manually.

So let's finish:

1. Redirection of subscribers when the site is updated.

If you are updating or testing your website on hosting, you can redirect visitors to the same page. For this you need to add the following code to the .htaccess file:

Order deny,allow
deny from all
allow from 123.123.123.123
ErrorDocument 403 /page.html

allow from all

Replace 123.123.123.123 with your IP address, and also replace page.html on the other side, as most of the supporters who have visited the site.

2. Song side with milk 404.

If users go to a page on your site that doesn’t exist, then it has a 404 warning. If you want to create a page on your site, then write the following code in the htaccess file:

ErrorDocument 404 /404.html

In this case, you can manually redirect the advertisers to the main page of the site.

3. Redirect to moved or renamed pages.

If you have renamed or moved some pages on the site and want your publishers to launch new pages, as they appear behind the old address, then write the following code in the htaccess file:

Redirect 301 /old.html http://yoursite.com/new.html

You can also vikorize such a redirect so that the site is not ruined for sound systems.

Is there a file on your dad’s website? index, any kind of treasurer might wonder what kind of files lie in it.

To avoid such speeches, write the following code:

Options All-Indexes

On some hosting sites, this function is written out manually, so you won’t be able to get into trouble with this one.

5. Create a beautiful URL.

Of course, between the two of them, the Persha looks much more attractive.

http://yoursite.com/about
http://yoursite.com/pages/about.html

For additional help with the htaccess file, the Apache module called mod_rewrite You can rework your messages to be more beautiful and short.

Butt axis with code:

RewriteEngine on
RewriteRule ^about/$ /pages/about.html [L]
RewriteRule ^features/$/features.php [L]
RewriteRule ^buy/$/buy.html [L]
RewriteRule ^contact/$ /pages/contact.htm [L]

P.S. There are a number of sites on the Internet, using which you can automatically edit the .htaccess file. For example htaccesseditor.com.

P.P.S. To create such a file from scratch, you need to open, for example, notepad, enter it in a new row

AddHandler application/x-httpd-php .php .htm .html