在WordPress网站被黑客攻击后清除缓存

8

我的Wordpress网站被黑客攻击了。它将用户重定向到一些垃圾网站。 自那以后,我已经清理了网站,问题不再发生。

问题是,我的访问者仍然会被重定向到垃圾网站,直到他们清除缓存或停止重定向并重新加载页面。

我不确定该怎么做来解决这个问题。我知道我无法远程删除用户的缓存,但肯定有一些方法可以告诉他们的浏览器,在重定向开始之前,网站上有更改。

我已经将此代码添加到网站中:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

有什么想法吗?

1
应该能够使用头文件来完成,使用元标记的问题在于当发送“304未修改”时,HTML甚至不会被提供,因此浏览器无法看到它。 - Lawrence Cherone
1
请查看以下文章:https://www.2-viruses.com/how-to-fix-google-redirect-virus-browser-hijacker-problem - Gufran Hasan
@lawrence-cherone 感谢您的回答。 我尝试将以下内容添加到htaccess文件中: <IfModule mod_headers.c> Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0 </IfModule>并将以下内容添加到我的header.php文件中: header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1. header("Pragma: no-cache"); // HTTP 1.0. header("Expires: 0"); // Proxies.但仍然无法正常工作。 - Jan Pulpán
您需要启用mod_headers模块才能使其正常工作,请参见https://dev59.com/2mYr5IYBdhLWcg3wfKL_ - 要在PHP中执行此操作,只需将标头添加到配置文件中或其他地方,WordPress没有关闭缓存的插件吗?如果没有,我会很惊讶。 - Lawrence Cherone
如果所有其他方法都失败了,请确保您没有被感染,如果您只是从备份中恢复,则这些问题将会再次出现。 - Lawrence Cherone
尝试在控制台/终端中查看标头:curl -I http...your..domain,如果您看到30x,则表示出现了问题。然后查看Web服务器apache/nginx。您可以将echo 'test'添加到index.php中,并在浏览器或终端中检查标头。 - gregman
2个回答

0
  1. 使用插件(例如Wordfence Security)运行恶意软件扫描。 (它将帮助您找到恶意文件和代码)
  2. 打开WP-Content文件夹
  3. 打开“Cache”文件夹
  4. 然后打开每个文件夹并删除其中存储的内容。 不要删除文件夹(您也可以使用插件(例如WP Fastest Cache)清除缓存。

0

我也遇到了这个问题,我在我的.htaccess文件中添加了这段代码来解决它。请尝试一下。

<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/html "access plus 3 days"
ExpiresByType text/xml "access plus 1 seconds"
ExpiresByType text/plain "access plus 1 seconds"
ExpiresByType application/xml "access plus 1 seconds"
ExpiresByType application/rss+xml "access plus 1 seconds"
ExpiresByType application/json "access plus 1 seconds"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-ico "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/pdf "access plus 1 month"
<IfModule mod_headers.c>
   Header unset ETag
   Header unset Pragma
   Header unset Last-Modified
   Header append Cache-Control "public, no-transform, must-revalidate"
   Header set Last-modified "Mon, 1 Apr 2017 10:10:10 GMT"
 </IfModule>
 </IfModule>

1
如果你遇到500错误,那么可能会起作用,请注释掉if条件,然后检查mod_headers.c是否已启用。 - Lawrence Cherone
谢谢你的提示。不幸的是,它对我没有用。 - Jan Pulpán
你可以在这里检查 - mezinami.cz - Jan Pulpán
它会重定向,但是只要我清除缓存,它就可以正常工作。因此,我认为恶意软件已经不存在了。 - Jan Pulpán
好的,我需要进一步查看。我不理解的是,为什么一旦我清除缓存,重定向就停止了?我在多台电脑上尝试过,结果都一样。 - Jan Pulpán
@JanPulpán,我刚刚发现了一篇有用的文章。希望它有意义 https://fixmywp.com/blog/add-expire-headers-wordpress-site.php - Gufran Hasan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接