douan5151 2019-02-26 10:33
浏览 81

停止与模式匹配的wordpress缓存URL,或者如果用户已登录且存在cookie

I host a wordpress site on apache / mysql with Hostinger. In addition to some posts and simple content pages there is a parent page /members/ and child pages under it which are available only for logged in members, like so:

/members/
/members/lorem/
/members/ipsum/
/members/dolor/

I think it could be done with .htaccess is to check for a wordpress logged in cookie and set cache / expires headers to stop caching.

I'm looking for a way to use .htaccess to prevent caching of any pages with the word member in the URL. I've seen some examples that work using <FilesMatch> but they only check the filename and extension, not the whole URL to match a pattern before the filename. I've also seen that <location>, <directory> and <directorymatch> could be used but only if the host provider gives you server access to do so which I don't have.

I can't find a solution that works using the .htaccess file or a combination with wordpress and custom PHP.

My permalinks settings in wordpress is set to 'Post name' and my .htaccess file currently contains:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Note: I don't want to use a plugin to do this for various reasons.

  • 写回答

1条回答 默认 最新

  • dqvzfp6468 2019-02-27 12:43
    关注

    I've figured it out. This is what worked in my .htaccess file

    # BEGIN custom CACHE BUSTING
    #<IfModule mod_rewrite.c>
        ## No ETags so cache headers work better
        #FileETag None
        #Header unset ETag
    
        ## Look for URLS starting with /member with anything after it, or containing login
        #RewriteCond %{REQUEST_URI} ^\/(member(.*)|(.*)login(.*))
        #RewriteRule ^ - [E=NOCACHE:1] ## Set our env variable
        #Header always set CHECK_NOCACHE "%{REDIRECT_NOCACHE}e" env=REDIRECT_NOCACHE ##custom header for testing, will show up if URL pattern matches above
    
        ## Do all cache busting, note NOCACHE is give a REDIRECT_ prefix, so have to read and check it by it's new name REDIRECT_NOCACHE
        #Header unset Pragma env=REDIRECT_NOCACHE
        #Header unset Cache-Control env=REDIRECT_NOCACHE
        #Header unset Last-Modified env=REDIRECT_NOCACHE
        #Header always set Pragma "no-cache" env=REDIRECT_NOCACHE
        #Header always set Cache-Control "s-maxage=0, max-age=0, no-cache, no-store, must-revalidate" env=REDIRECT_NOCACHE
        #Header always set Expires "Thu, 1 Jan 1970 00:00:00 GMT" env=REDIRECT_NOCACHE
    #</IfModule>
    # END custom CACHE BUSTING
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教