📜 ⬆️ ⬇️

Optimizer secrets

Since I do not do this, but only prepare the ground for their work, I write what is known to some, but interesting to many.

1) Last-Modified and If-Modified-Since Headers

To properly index your site's search engines, each page should produce a Last-Modified header and correctly process requests with the If-Modified-Since condition. If the page has not changed since the time specified in the request, the server should issue “HTTP / 1.1 304 Not Modified.”

An example of php-code for the very simple case when the script contains all the data:
')
header ("Last-Modified:". gmdate ("D, d MYH: i: s", filemtime ($ _ SERVER ['SCRIPT_FILENAME'])). "GMT");

Paste at the beginning of each page.

Added: In other cases, instead of “filemtime ($ _ SERVER ['SCRIPT_FILENAME'])” you need to substitute the last date of the change of the data displayed on this page.

2) Gzip compression

Significantly reduces the page load time.

Php code, insert the first line:

ob_start ('ob_gzhandler');

3) Proper caching of images by the browser

Pictures should be cached for at least a month. For an HTTP request for a picture, you should see a header like “Cache-Control: max-age = 999999”
To do this, insert

ExpiresActive On
ExpiresByType image / gif "access plus 3 month"
ExpiresByType image / jpeg "access plus 3 month"

in .htaccess in the root of the site.

For those who have not loaded the module, add

LoadModule expires_module libexec / mod_expires.so
AddModule mod_expires.c

to the begining.

4) Fix problems with “Options + MultiViews”

For those who use "Options + MultiViews" - there may be problems with search engines. With the “default” settings in Apache, he has problems with choosing a file (php scripts do not have mime-type). To treat this problem, insert

AddType text / html php

in .htaccess in the root of the site.

5) Mirrors

If your site has a mirror, in order to avoid a possible ban in search engines, insert

User-Agent: *
Host: www.sayt.ru

in robots.txt at the root of the site.

6) Hosts www.site.ru and site.ru

At the website address the site should be issued the header "HTTP / 1.1 301 Moved Permanently" There will be, for example, the correct calculation of the TIC.

7) Add your own :-)

Source: https://habr.com/ru/post/569/


All Articles