WordPress如何禁止SQL查询或禁止垃圾信息请求,也是为了提高网站的安全性,若我们使用Apache引擎或LAMP环境,我们只需要在根目录的 .htaccess 文件中添加以下代码即可。
1、禁止机器人请求
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.wordpress.dev.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
</IfModule>
2、禁止SQL查询
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC]
RewriteRule ^(.*)$ - [F,L]
RewriteCond %{QUERY_STRING} \.\.\/ [NC,OR]
RewriteCond %{QUERY_STRING} boot\.ini [NC,OR]
RewriteCond %{QUERY_STRING} tag\= [NC,OR]
RewriteCond %{QUERY_STRING} ftp\: [NC,OR]
RewriteCond %{QUERY_STRING} http\: [NC,OR]
RewriteCond %{QUERY_STRING} https\: [NC,OR]
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|%3D) [NC,OR]
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(\[|\]|\(|\)||ê|"|;|\?|\*|=$).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*("|'|<|>|\|{||).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(%24&x).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(%0|%A|%B|%C|%D|%E|%F|127\.0).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(globals|encode|localhost|loopback).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(request|select|insert|union|declare).* [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in_.*$
RewriteRule ^(.*)$ - [F,L]
</IfModule>
3、禁止垃圾信息请求
<ifModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} enter|separated|query|strings|here [NC]
RewriteRule .* http://www.%{HTTP_HOST}/$1? [R=301,L]
</ifModule>
当然,提高网站的安全性不止这些,更多还需靠自己在运营过程中发现。
-
WordPress 6.5 新功能 - 字体库字体库是 WordPress 6.5 的亮点之一
-
WordPress6.5新功能-声明式插件依赖在 WordPress 6.5 中,插件依赖变简单了
-
WordPress 6.5 新功能 - 支持 AVIFWordPress 6.5 新功能 - 支持 AVIF
-
WordPress 6.5移除区块样板菜单项的方法WordPress 6.5新增的区块样板菜单项,可将不同区块组合成一个新的区块模板,方便重复使用。
-
WordPress做多语言企业网站近期常用小伙伴问追格小编,有没有计划做双语WordPress企业官网主题。
-
WordPress插件:LiteSpeed Cache 缓存插件LiteSpeed Cache是一款实用的WordPress缓存插件,专为使用LiteSpeed服务器的用户设计。它能显著提高网站加载速度,改善用户体验。
暂无评论,抢个沙发...