Cache-Control: no-transform header in WordPress without plugin - wordpress

How can I insert a Cache-Control: no-transform HTTP header in a WordPress site without using a plugin? Can it can be inserted in .htaccess or function.php?

You should be able to add the Cache-Control header with .htaccess, if it's being served with Apache and you have .htaccess enabled:
Header set Cache-Control "no-transform"

Related

Clear cache for static website upon deploy with Heroku?

I have a static website hosted with Heroku's hobby tier. I have an issue where everytime I push a new deployment from my GitHub repository, my stylesheet doesn't update for hours (even though my HTML does). As the stylesheet displays correctly on an incognito tab and after clearing "Cached Images and Files," I assume locally cached website files are the issue. Is there a way to bypass this in order to update my CSS stylesheet after every deploy?
My stylesheet is ~600 lines if it matters.
Adding the following to my htaccess file worked for me.
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
This prevents caching for HTML, HTM, JS, and CSS files.

Wordpress / Prevent Server from Caching CSV Files

I am creating a CSV File with PHP and save it to the Server.
The Server Cache is enabled, but this makes the CSV File being cached too.
I am looking for a way to prevent that. Without Plugins...
What I tried: adding code to htaccess (which also prevents the browser from caching the file, please don#t focus on answers related to htaccess and browser-caching, thanks!).
And I also tried to add some header() Code .. but I am not sure where.
I added this when I create the File:
header('Content-Type: text/csv');
header('Content-Disposition: attachment filename="sample.csv"');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
But it's not working when I open the file - it gets cached. But I guess this is the false spot for adding this code. But where else?
I also tried to add an action to 'init' and ask if the called file is the file I don't want to be cached, but of course, functions.php is not called when opening a file from the server.
Does someone have an Idea?
Put this code in .htaccess file , it may help you . prior puting this make sure you have done backup of your website.
<FilesMatch "\.(pdf|csv|doc)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
</IfModule>
</FilesMatch>

Switching Wordpress Multi-site to HTTPS - redirection loop

I am recovering a wordpress multi-site installation and switching it to https. The apache configuration is well done and wordpress can be accessed using ssl.
However, all links from wordpress are still referring to the non http version.
When I try to modify the home and siteurl variables in wp_options, Wordpress is creating a redirection loop.
From curl when getting /:
HTTP/1.1 301 Moved Permanently
Date: Tue, 26 Dec 2017 12:17:27 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Location: https://www.example.com/
Adding this does not affect anything.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
I tried:
clearing cache
clearing cookies
disabling all extensions.
checking apache's error logs.
deleting .htaccess
But I am still unsuccessful.
Any ideas on what I could do?

nginx Cross-Origin Resource issues

I've read almost every post on stackoverflow in regards to CORS and whatever I try does not work. Here is my setup:
Ubuntu (digital ocean)
nginx
cdn: cdn77.com (not amazon)
cloudflare
wordpress with wp fastest cache
Each time a new setting was done I've purged cloudflare and restarted nginx.
This is what I've tried:
.htaccess (doesn't work)
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"
Header set Access-Control-Allow-Methods "GET, PUT, POST"
</FilesMatch>
</IfModule>
nginx (doesn't work)
add_header Access-Control-Allow-Headers "X-Requested-With";
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS";
add_header Access-Control-Allow-Origin "*";
I am pulling my hair out trying to figure out why font awesome wont show its icons on my site which is on a different domain.
.htaccess files are apache only, it will never work for Nginx.
With nginx it should work if theses headers are added to the font HTTP response... but it seems you do not own the fonts and you take the fonts from another website. The CORS headers need to be set by this website, not yours. Check what are theses headers on the fonts, and check that your website is allowed to use the fonts from there (else you will have to download the fonts on your website and add the headers on an nginx location based on the font extension.
I guess you confuse CORS headers and CSP headers (**C**ontent **S**ecurity **P**olicy). Where you can give a list of allowed resources for your website.

How to send "Cache-Control: no-cache" header in Piwik API responses

I have a Piwik install sitting behind a varnish-caching server. My problem is varnish is by default caching responses to my API calls. Unfortunately, I don't have direct access to the varnish server, so I need to send the
"Cache-Control: no-cache"
header with my API responses. Is there a setting or a way to modify my piwik install to accomplish this? Thanks!
Add to .htaccess in your piwik install, core/API/ folder:
<Files Request.php>
Header set Cache-Control "no-cache"
</Files>
If you need to add the header to other URLs, follow the same pattern.
Note that Piwik already adds Cache-Control: max-age=0 to these responses, so if that's not working for you on the Request.php path you probably want to add this to .htaccess in the folder with piwik.js (root of piwik install) as well:
<Files piwik.php>
Header set Cache-Control "no-cache"
</Files>

Resources