Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决在不使用htaccess的情况下利用wordpress中的浏览器缓存问题_Php_Wordpress_.htaccess_Caching - Fatal编程技术网

Php 如何解决在不使用htaccess的情况下利用wordpress中的浏览器缓存问题

Php 如何解决在不使用htaccess的情况下利用wordpress中的浏览器缓存问题,php,wordpress,.htaccess,caching,Php,Wordpress,.htaccess,Caching,我有一个用WordPress和Windows Plesk面板托管的网站。由于IIS的原因,这些类型的主机大多不支持htaccess 我想解决在wordpress中利用浏览器缓存而不使用htaccess文件的问题 我试过下面的非htaccess缓存的东西,但该网站显示的是空白屏幕 <?php if (isset($_GET['img'])) {$filename = $_GET['img'];}else{exit;} $allowed = array('gif','png','jpg');

我有一个用WordPress和Windows Plesk面板托管的网站。由于IIS的原因,这些类型的主机大多不支持htaccess

我想解决在wordpress中利用浏览器缓存而不使用htaccess文件的问题

我试过下面的非htaccess缓存的东西,但该网站显示的是空白屏幕

<?php

if (isset($_GET['img'])) {$filename = $_GET['img'];}else{exit;}
$allowed = array('gif','png','jpg');
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {exit;}
$stc = 31536000;
$ts = gmdate("D, d M Y H:i:s", time() + $stc) . " GMT";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header("Expires: $ts");
header("Cache-Control: max-age=$stc, public");
header("Pragma: cache");
ob_clean();
flush();
readfile($filename);
exit;
?>

您好,您可以通过以下操作在Gtmetrix中获得分数

一些主机提供商不喜欢htaccess,因此我更喜欢使用超高速缓存插件,并进行所有必要的配置

然后在Wordpress主题的header.php中添加以下内容

<?php

$stc = 31536000;
$ts = gmdate("D, d M Y H:i:s", time() + $stc) . " GMT";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header("Expires: $ts");
header("Cache-Control: max-age=$stc, public");
header("Pragma: cache");
ob_clean();
flush();
exit;
?>

检查后,一定要让我知道


谢谢

您好,您可以通过以下操作在Gtmetrix中获得分数

一些主机提供商不喜欢htaccess,因此我更喜欢使用超高速缓存插件,并进行所有必要的配置

然后在Wordpress主题的header.php中添加以下内容

<?php

$stc = 31536000;
$ts = gmdate("D, d M Y H:i:s", time() + $stc) . " GMT";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header("Expires: $ts");
header("Cache-Control: max-age=$stc, public");
header("Pragma: cache");
ob_clean();
flush();
exit;
?>

检查后,一定要让我知道


谢谢

IIS使用web.config文件,而不是.htaccess。如果有任何方法可以实现利用浏览器缓存,我在主机文件夹中找不到任何web.config文件。我已经很长时间没有使用IIS了,所以我不能说得更具体了。如果有疑问,为什么不询问您的主机?IIS使用web.config文件,而不是.htaccess。是否有任何方法可以实现利用浏览器缓存,我在主机文件夹中未找到任何web.config文件。我已经很长时间没有使用IIS了,所以我不能说得更具体了。如果有疑问,为什么不问问你的主持人?嗨,这有助于我在GTmetrix中获得一个分数,谢谢你,但是你能告诉我这有什么用吗。basename($filename)在这里?嗨,它帮助我在GTmetrix中获得了一个分数,谢谢你,但是你能告诉我它的用途吗。这里是basename($filename)?