是否可以检查用户管理员是否使用htaccess

时间:2015-07-22 09:49:52

标签: wordpress .htaccess mod-rewrite mod-expires mod-headers

如果用户管理员喜欢current_user_can('管理员')

,我想发送无缓存标头

因此浏览器不会缓存一些resurces。 (为了防止每次ctrl + f5)

也欢迎近乎解决方案。

在搜索过程中,我发现了

46.58762816
30.50477684
27.4195249
47.98157313
44.55425608
30.21066503
34.27381019
48.19934524
46.82233375
46.05077036
42.63647302
40.11270346
48.04909583
24.18660332
24.47549276
44.45442651
19.24542913
37.44141763
28.41079638
21.69325455
31.32887617
26.26988582
18.19898804
19.01329026
28.33846808

是否可以通过上述方法发送no-cache标头?

2 个答案:

答案 0 :(得分: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 =以秒为单位的时间..将其设置为1800或持续30分钟

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

答案 1 :(得分: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

相关问题