• Home
  • WordPress
  • web Hosting
    • Free hosting
    • Cheap Hosting
    • comparison cloud , vps, shared, wordpress
    • managed wordpress hosting
    • managed cloud hosting
  • page Speed
  • Deals
  • Services
  • About

RAaz Kumar .com

wordpress tutorials seo hosting etc


nginx add last modified header (remove, php wordpress)

last modified header

 

Syntax: add_header name value [always];
Default: —
Context: http, server, location, if in location

Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0). Parameter value can contain variables.

There could be several add_header directives. These directives are inherited from the previous configuration level if and only if there are no add_header directives defined on the current level.

If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.

 

add header Last-Modified

 

Nginx adds last modified date for files cached html files in WordPress cached pages automatically rather than published date, it adds cached or stored date in SSD or disk.

for wordpress we need to add this plugin as of now working ..  Last-Modified and If-Modified-Since Headers

Nginx Module ngx_http_headers_module

 

if_modifeid_since exact;

exact: Returns 304 Not Modified if the date and time specified in the HTTP header are an exact match with the actual requested file modification date. If the file modification date is earlier or later, the file is served normally (200 OK response).

Disable Last modified header in nginx

by default nginx adds last modified header for static files css,js images and html which are stored in disk. not from mysql for this we need to tweak php.

if_modified_since off;

Removing Last-Modified header:

add_header Last-Modified “”;

 

 

Cloudflare Nginx Last modified header

When both Last-Modified and Etag headers are absent from the origin server response, Smart Edge Revalidation will use the time the object was cached on Cloudflare’s edge as the Last-Modified header value.

 

Problem: cache ttl sets for 2 hours the page last modified time always within 2 hours, google may ignore the last modified header or updated genuine pages.

 

Change alter the last modified date

 

add_header Last-Modified $date_gmt;
if_modified_since off;
etag off;

As for the last line, if you really want to hide a true last-modified date, then you must hide the ETag header too since it leaks timestamps.

add_header Last-Modified $date_gmt;   (the present date prints)

ssi_last_modified on

Allows preserving the “Last-Modified” header field from the original response during SSI processing to facilitate response caching.

Add headers Last modified exact date with PHP

 

<?php
//get the last-modified-date of this very file
$lastModified=filemtime(__FILE__);
//get a unique hash of this file (etag)
$etagFile = md5_file(__FILE__);
//get the HTTP_IF_MODIFIED_SINCE header if set
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);
//get the HTTP_IF_NONE_MATCH header if set (etag: unique file hash)
$etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false);

//set last-modified header
header(“Last-Modified: “.gmdate(“D, d M Y H:i:s”, $lastModified).” GMT”);
//set etag-header
//header(“Etag: $etagFile”);
header(“ETag: \”$etagFile\””);
//make sure caching is turned on
header(‘Cache-Control: private, must-revalidate, proxy-revalidate, max-age=3600’);

//check if page has changed. If not, send 304 and exit
if (@strtotime($_SERVER[‘HTTP_IF_MODIFIED_SINCE’])==$lastModified || $etagHeader == $etagFile)
{
header(“HTTP/1.1 304 Not Modified”);
header(“Vary: Accept-Encoding”);
exit;
}
?>

 

Last modified header plugins for WordPress

 

LH Add Headers

 

Check HTTP Headers in linux terminal

 

curl -I https://sarkariresultz.in/iti-jobs/

 

root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# curl -I https://sarkariresultz.in/iti-jobs/
HTTP/2 200
date: Sun, 19 Mar 2023 10:04:52 GMT
content-type: text/html
last-modified: Sat, 18 Mar 2023 06:26:48 GMT  (ETAG on)
vary: Accept-Encoding, Cookie
cache-control: no-cache, no-store, must-revalidate
x-rocket-nginx-serving-static: HIT
cf-cache-status: DYNAMIC

strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
server: cloudflare
cf-ray: 7aa4e4c7a9949bd7-FRA
alt-svc: h3=”:443″; ma=86400, h3-29=”:443″; ma=86400

 

 

for wordpress add this to theme function code

This worked for me on all posts (Not pages)– added into theme functions.php file:

wordpress variables

add_action(‘wp’, ‘last_if_modified_headers’ );

function last_if_modified_headers() {
global $post;
if(isset($post) && is_single()){
$LastModified_unix = strtotime($post->post_modified);
$LastModified = gmdate(“D, d M Y H:i:s \G\M\T”, $LastModified_unix);
$IfModifiedSince = false;

if (isset($_ENV[‘HTTP_IF_MODIFIED_SINCE’])) {
$IfModifiedSince = strtotime(substr($_ENV[‘HTTP_IF_MODIFIED_SINCE’], 5));
}
if (isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’])) {
$IfModifiedSince = strtotime(substr($_SERVER[‘HTTP_IF_MODIFIED_SINCE’], 5));
}

if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) {
header($_SERVER[‘SERVER_PROTOCOL’] . ‘ 304 Not Modified’);
exit;
}

header(‘Last-Modified: ‘. $LastModified);
}
}

 

use this plugin  (how to create a WordPress plugin)

last-modified-and-if-modified-since-headers

 

copy the following text to the header.php file:

header(“Last-Modified: ” . date(‘r’,strtotime($post->post_modified)));

header("Last-Modified: " . date('r',strtotime($post->post_modified)));

 

However, this code applies for posts and pages only. It’s useless for the main page, archives, recent comments, and taxonomy.

<?php
$LastModified_unix = 1294844676;
$Last Modified = gmdate(«D, d M Y H:i:s \G\M\T», $LastModified_unix);
$IfModifiedSince = false;
if (isset($_ENV[‘HTTP_IF_MODIFIED_SINCE’]))
  $IfModifiedSince = strtotime(substr($_ENV[‘HTTP_IF_MODIFIED_SINCE’], 5));
if (isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’]))
  $IfModifiedSince = strtotime(substr($_SERVER[‘HTTP_IF_MODIFIED_SINCE’], 5));
If ($IfModifiedSince && $IfModifiedSince >= &LastModified_unix) {
  header ($_SERVER[‘SERVER_PROTOCOL’] . ‘ 304 Not Modified’);
  exit;
}
header(‘Last-Modified: ‘ . $LastModified);
?>


global $wpdb;

$wp_last_modified_date = $wpdb->get_var(“SELECT GREATEST(post_modified_gmt, post_date_gmt) d FROM $wpdb->posts WHERE post_status = ‘publish’ ORDER BY d DESC LIMIT 1”);
$wp_last_modified_date = max($wp_last_modified_date, get_lastcommentmodified(‘GMT’));

$last_modified = mysql2date(‘D, d M Y H:i:s’, $wp_last_modified_date, 0) . ‘ GMT’;

 

//set last-modified header
header( “Last-Modified: “.$last_modified);

Related topics:

  1. what is If-Modified-Since HTTP header how to add to WordPress website
  2. Cache control Header & expires headers How to set Properly
  3. enable browser caching in wordpress apache nginx caching headers explained
  4. how to enable KeepAlive connections in apache nginx wordpress
  5. nginx fastcgi cache wordpress how to configure

tutorials

  • Vivek Bindra Videos Transcription (business strategy)
  • git commands
  • new relic php agent install in 3 steps
  • new relic mysql install integration - 2 ways fix problems
  • new relic installation linux (infrastructure agent , php, mysql , nginx)
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • Redis performance metrics & tuning for nginx apache ubuntu & debian
  • Devops course Syllabus topics PDF AWS, Azure, cisco, redhat
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • how to create a website free of cost on google
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • nginx server tutorials (installation, configuration, performance tuning, security)
    • php fpm ondemand vs dynamic vs Static (the dynamic pool problem)
    • nginx installation on ubuntu 20.04 LTS
    • monitor nginx request with nginx status amplify datadog new relic
    • SSL faster reduce TLS hand shake improve https performance
    • nginx rate limiting explained by location time specific url
    • datadog nginx integration installation process
    • newrelic nginx integration process and errors fix and metrics
    • php fpm seems busy fixed warning and max children reached to handle max connections / requests
    • Php fpm configuration for 1000 concurrent connections server busy max children reached
    • enable brotli compression nginx brotli vs gzip
    • nginx upstream response is buffered to a temporary file
    • php fpm install ubuntu 20.04 nginx
    • install phpmyadmin ubuntu nginx 22.04
    • upgrade php fpm ubuntu nginx 7.4 to 8.2
    • nginx add last modified header (remove, php wordpress)
    • php fpm dynamic pool manager settings
    • nginx fastcgi cache purge
    • nginx open file limit ulimits sysctl
    • nginx rewrite rules with examples 301 redirection
    • fix error 520 522 524 on cloudflare wordpress godaddy nginx etc
    • nginx fastcgi cache wordpress how to configure
    • install LEMP Stack on 22.04 LTS Nginx MySQL PHP fpm #wordpress #digital ocean
    • Apache vs nginx (connection handling, modules, memory usage)
    • Pagespeed module install, configure, monitor, errors ft nginx &apache
    • nginx errors (504,502, 413, unable to start, syntax errors)
    • nginx conf explained best config file performance tuning tips nginx.conf location errors tutorial
    • use nginx as reverse proxy and load balancer for apache wordpress
    • Letsencrypt SSL Installation on apache/Nginx ubuntu / debian wordpress
    • nginx modules list (enable, disable, upgrade, install dynamic module)
    • php fpm pool manager configuration settings based on server spike high cpu wordpress
    • php fpm restart nginx ubuntu enable status page, monitor etc
    • what is TTFB & how to Reduce it (server response time) Google pagespeed
    • letsencrypt install configure on ubuntu / debian nginx
    • Top 10 tips to improve nginx server security
    • nginx performance tuning
  • MySQL Tutorial (create,connect database, update tables, export etc) Documentation & TIPS
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • redis install ubuntu 20.04 with wordpress php redis mysql configuration
  • ubuntu tutorials installation download issues etc
  • Php tutorials
  • HTML & CSS Tutorials
  • Core Java Tutorial Free online
  • Linux sysadmin tutorials linux system administrator
  • apache server tutorial (install,config, performance tuning, security, error handling)

 

 

wordpress Pagespeed optimization

Digitalocean free $100 Credit

Cloudways Review pricing promo codes

Siteground cpu limits Pricing

Shared Hosting

Managed wordpress Hosting

Managed Hosting Cloud server

VPS Hosting

Cloud Hosting – Unmanaged

Google cloud Pricing

Aws Pricing

Azure pricing

nginx server tutorials

apache server tutorials

linux sysadmin tutorials

mysql Commands list pdf

LEMP Install Ubuntu

Mysql Performance Tuning

Nginx Performance tuning

Linux Performance tuning

Php -fpm performance tuning

Redis Performance tuning

linux server security

nginx security best practices

wordpress security plugins

 

 

wordpress

 

Top 5  WP Google Analytics Plugins

WP Backup Plugins

Wp Comment Plugins

Top wordpress Security Plugins

WP Seo Plugins

WP Caching Plugins

Best Adsense Plugins for WordPress

Wp social Sharing Plugins

autoshare social media plugins

WP speed Optimization Plugins

Speedup WordPress google Score

More Wp tuts

Server Admin Cloud

 

Installing Nginx LEMP On ubuntu

Installing apache Lamp ubuntu

nginx fastcgi cache enable

php – fpm install  & Configuration

Opcache install & Configure

php -fpm pool manager explained

Mysql Install & Configuration

Redis Object cache install & configure

 

Nginx as Reverse Proxy and Load balancer

Load Balance / auto scaling in google cloud

Linux Commands PDF

Mysql Commands Pdf

Letsencrypt tutorial

mysqldump export & import 

Pagespeed Module install & configure

nginx.conf best file

mysql.conf best file

upgrade ubuntu

© 2023 - All Rights Reserved Disclaimer & Privacy Policy