-2

如果用户是像 current_user_can('administrator') 这样的管理员,我想发送无缓存标头

所以浏览器不会缓存一些资源。(为了防止每次都按 ctrl + f5 )

近解决方案也欢迎。

在搜索过程中我发现

RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_|wp-postpass_) [NC]

是否可以使用上述方法发送无缓存标头?

4

2 回答 2

0

简单地说,您可以将管理区域放在公共网站文件夹以外的单独文件夹中,并为该文件夹设置缓存,如下所示:

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

max-age = time in seconds .. 将其设置为 1800 或持续 30 分钟

除此之外,不,htaccess 无法检查“用户”是否为管理员,您必须使用 php

于 2015-07-22T09:56:55.400 回答
0

htaccess 无法访问会话,因此您无法检查用户是否已登录或其中的任何内容。但如前所述,您可以在 PHP 中检查它,并且当您使用 Wordpress 时,您可以将它放在您的 functions.php 中:

function admin_nocache() {
    if(is_admin()) {
        nocache_headers();
    }
}
add_action( 'init', 'admin_nocache' );

https://codex.wordpress.org/Function_Reference/nocache_headers

于 2015-07-22T10:06:15.147 回答