OpenLiteSpeed针对WordPress的伪静态及安全规则 - 技术宅银魂 - 科技改变生活 - 万事屋

OpenLiteSpeed针对WordPress的伪静态及安全规则

根据OpenLiteSpeed的说法不要用.htaccess,这样会拖慢速度,所以直接在后台规则里编辑:

RewriteEngine On
Options -Indexes
DirectoryIndex index.php index.html

# ========== 安全防护规则(OLS环境有效) ==========
# 禁止直接访问敏感配置文件
RewriteRule ^wp-config\.php$ - [R=404,L]
RewriteRule ^wp-config-sample\.php$ - [R=404,L]
RewriteRule ^readme\.html$ - [R=404,L]
RewriteRule ^license\.txt$ - [R=404,L]
RewriteRule ^wp-admin/install\.php$ - [R=404,L]
RewriteRule ^wp-content/debug\.log$ - [R=404,L]

# 禁止目录浏览(Options -Indexes 已开启,双重防护)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^$ - [R=404,L]

# 拦截恶意扫描:php探针、webshell、后门常见文件名
RewriteRule (phpinfo|shell|backdoor|eval|cmd|大马|小马)\.php$ - [R=403,L]

# 拦截路径遍历攻击 ../
RewriteCond %{QUERY_STRING} \.\./ [NC,OR]
RewriteCond %{REQUEST_URI} \.\./ [NC]
RewriteRule ^ - [R=403,L]

# 拦截空User-Agent恶意爬虫扫描
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^ - [R=403,L]

# 拦截恶意请求参数(SQL注入特征)
RewriteCond %{QUERY_STRING} union|select|and|or|insert|delete|drop [NC]
RewriteRule ^ - [R=403,L]

# =====================  HTTP 强制跳转 HTTPS =====================
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.rei3.com/$1 [R=301,L]

# ===================== 2. 裸域名 301跳转 www =====================
RewriteCond %{HTTP_HOST} ^rei3\.com$ [NC]
RewriteRule ^(.*)$ https://www.rei3.com/$1 [R=301,L]

# ===================== 3. WordPress 标准伪静态 =====================
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# ========== 静态资源缓存优化(提升速度) ==========
<FilesMatch "\.(jpg|jpeg|png|gif|webp|ico|css|js|woff|woff2|ttf)$">
    Header set Cache-Control "public, max-age=2592000"
</FilesMatch>

 

请登录后发表评论

    没有回复内容

万事屋新帖