SetEnvIf X-SSL-Emu on HTTPS=on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
<FilesMatch "\.(ttf|otf|eot|svg)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1536000 seconds"
ExpiresByType image/x-icon "access plus 1536000 seconds"
ExpiresByType image/jpeg "access plus 1536000 seconds"
ExpiresByType image/png "access plus 1536000 seconds"
ExpiresByType image/gif "access plus 1536000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 1536000 seconds"
ExpiresByType text/css "access plus 1536000 seconds"
ExpiresByType text/javascript "access plus 1536000 seconds"
ExpiresByType application/javascript "access plus 1536000 seconds"
ExpiresByType application/x-javascript "access plus 1536000 seconds"
ExpiresByType text/html "access plus 1536000 seconds"
ExpiresByType application/xhtml+xml "access plus 1536000 seconds"
</ifModule>
add_action( 'template_redirect', 'HTTP_Headers_Last_Modified' );
function HTTP_Headers_Last_Modified() {
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( is_admin() ) ) {
return;
}
$last_modified = '';
// Для страниц и записей
if ( is_singular() ) {
global $post;
if ( !isset( $post -> post_modified_gmt ) ) {
return;
}
$post_time = strtotime( $post -> post_modified_gmt );
$modified_time = $post_time;
// Если есть комментарий, обновляем дату
if ( ( int ) $post -> comment_count > 0 ) {
$comments = get_comments( array(
'post_id' => $post -> ID,
'number' => '1',
'status' => 'approve',
'orderby' => 'comment_date_gmt',
) );
if ( !empty( $comments ) && isset( $comments[0] ) ) {
$comment_time = strtotime( $comments[0] -> comment_date_gmt );
if ( $comment_time > $post_time ) {
$modified_time = $comment_time;
}
}
}
$last_modified = str_replace( '+0000', 'GMT', gmdate( 'r', $modified_time ) );
}
// Cтраницы архивов: рубрики, метки, даты и тому подобное
if ( is_archive() || is_home() ) {
global $posts;
if ( empty( $posts ) ) {
return;
}
$post = $posts[0];
if ( !isset( $post -> post_modified_gmt ) ) {
return;
}
$post_time = strtotime( $post -> post_modified_gmt );
$modified_time = $post_time;
$last_modified = str_replace( '+0000', 'GMT', gmdate( 'r', $modified_time ) );
}
// Если заголовки уже отправлены - ничего не делаем
if ( headers_sent() ) {
return;
}
if ( !empty( $last_modified ) ) {
header( 'Last-Modified: ' . $last_modified );
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) && strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) >= $modified_time ) {
$protocol = (isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1');
header( $protocol . ' 304 Not Modified' );
}
}
}