通过.htaccess从“过期” - 标题中排除网址

时间:2014-08-14 07:57:05

标签: wordpress apache .htaccess caching mod-expires

ExpiresActive On
ExpiresDefault "access plus 1 day"
 [...]
RewriteRule .* index.php [L]

这是mod_expires加上相关RewriteRule的设置。他们完美地工作!但是我有一个特定的URL,不能被缓存。正则表达式为^/?nocache/。现在该目录(/nocache/)实际上并不存在;对它的请求 - 对于每个其他目录 - 都由" index.php"处理。

我的第一个想法是在它周围加<LocationMatch>,但是the documentation sais,不允许在&#34; .htaccess&#34;上下文。 我会想允许<FilesMatch>,但需要文件存在,我想((是吗?))。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以在.htaccess中使用RewriteRule指令:

ExpiresActive On
ExpiresDefault "access plus 1 day"
 [...]

RewriteEngine On
RewriteRule ^nocache - [E=NOCACHE:1]

SetEnvIf REDIRECT_NOCACHE 1 NOCACHE=1

# DO NOT cache /nocache/ URIs
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform" env=NOCACHE
Header set Pragma "no-cache" env=NOCACHE