I am having issues with server variables (like the page URL) being cached so that when you go to a new page, the variable that contains the server URL doesn't actually change.
I am able to fix it in my .htaccess file with this code:
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$">
<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 "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</FilesMatch>
So, I know the fix, but I need to know what is causing it because it's a WordPress site (and no, it's not being caused by plugins, I tested with a fresh WP install) and therefore my .htaccess file gets periodically overwritten by WordPress.
So I would like to know how to fix it on the server side, rather than using the .htaccess file. Would it be in the PHP variables? Or apache settings?
I called the webhost (godaddy) and the guy had no idea.
Thanks!
WordPress 5.6 added application passwords.
It wants to add this to .htaccess:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
I would try:
chmod 600 .htaccess
add_filter('wp_is_application_passwords_available', '__return_false');
Best wishes,
Mitchell
Related
I have a Wordpress site running a plugin called OpenHours. Basically, we program in our operating hours to the backend of the site and then have a page /hours/ which shows them. I have disabled every possible Caching feature in Wordpress and tried editing the .htaccess file with the below:
# DISABLE CACHING
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$">
<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 "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</FilesMatch>
We have a mobile app that basically links users to the webpage through their phone's browser, but anytime the link is clicked the page doesn't update (The plugin is configured to show "Currently Open" or "Currently Closed" based on time of day). Is there a way to force the page to update and not cache whenever it is visited?
I tried a query string but unfortunately the spot we insert the link in the app does not support any type of coding, just a straight link, so /hours/?rnd="+Math.random() and /hours/?rnd="+new Date().getTime() haven't worked.
You can set new headers for a specific page using the default PHP header function.
add_action("init", function() {
// TODO: Replace with the actual page ID or title
if(!is_page("page-without-cache")) return;
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
}, 10);
We used the init function to make sure that the header is sent before rendering the page.
And if you are using any cache plugin, you should be able to create a list of URLs or directories that you do not want to include or that you do not want to be cached. For example, in the WP Super Cache plugin, the option is located in the Advanced tab > Accepted Filenames & Rejected URIs section. By default, these paths are excluded from cache.
wp-.*\.php
index\.php
And in addition, WP have dedicated functions called nocache_headers or wp_nocache_headers, which you can also use to prevent caching. The functions are also using the default PHP header function.
I have a php script which copies an image to a folder every hour over writing the last image, the name of the image is always the same, image.jpg , im using ifttt to post the image to a website but the image posted is always the same image even though I have checked to see the image is different. so it must be posting the image from the cache? I added clearstatcache(); to the code but it doesn't work. is there any other way of clearing the cache so the actual image is posted? the image is hosted on a shared server. Thanks
$from = '/A1';
$files = scandir($from);
$to = '/A2';
if (!empty($files[2])) {
rename("{$from}/{$files[2]}", "{$to}/image.jpg");
}
clearstatcache();
solved with .htaccess file
<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|mp3|mp4|png|pdf|swf|txt)$">
<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 "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</FilesMatch>
Thanks for all your help!
I have a mini costum framework. All URLs are made on the index.php?op=ControllerName&Action=Methode&elemID=211 for example.
I generate the friendly URL of all specific URLs.
The problem is that I want to disable cache using .htaccess on all generated URLs.
So for elem 211 or 215 or 233 etc... I want that the server is getting the page not from cache.
Every time that the index.php is called I want that the browser use cache only for CSS, JavaScript, images and not for mysite.com/211-friendly_URL or mysite.com/215-friendly_URL_number_2
I used this but it didn't work
<ifmodule mod_headers.c>
<Files index.php>
FileETag None
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, 11 Jan 1984 05:00:00 GMT"
</Files>
</ifmodule>
thanks for your help;
I HAve a Website http://fbtricks.cf/
And It's Hosted in Hostinger.in
M Using PHP Extension, Because M Using a Common Header and Footer For All Files.
The Problem Is, I Have Made Changes to The Header and Footer. But Still The CHANGE is Not Reflecting in All Files. :(
And It's Not Just an ISsue in My Browser, But in Every Browser, The Old Header and Footer is Displaying Except in The Index File.
I THINK THAT, MAYBE IT"S HAPPENING BECAUSE THE SERVER HAS CACHED THE FILES.
Plz Provide Me With a Solution, as It's a Serious Issue For Me and My Website and Also For Website Visitors.
header file Link - http://fbtricks.cf/header.php
I'm not sure if this .htaccess file can override the global settings in Hostinger.
.htaccess:
<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, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
when I am debugging to ensure that some files are not cached and therefore reloaded anew each time, I frequently link files with something like
<script src="script/js.js?<?=time()?>"></script>
Is there some way I can do something in css to ensure background images are reloaded every time the page loads without making the style something other than a .css file? (php with css header for example)
#bg_div{
background: url(../images/darrow.png.....)
}
Thanks!
You could use .htaccess like this:
<filesMatch "\.(gif|jpg|png)$">
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 "Mon, 26 Jul 1990 05:00:00 GMT"
</ifModule>
</filesMatch>
This prevents all images to be cached. If you put the .htaccess file in a specific folder then images in this folder doesn't get cached.
Note that on sites with heavy load cache control should be carefully planned. Using a htaccess directive like this can VASTLY affect page load times.