Apache 在重写配置中检测到错误。在 .htaccess 文件中

问题描述 投票:0回答:1

我网站的 cPanel 出现错误,当我尝试启用 HOTLINK PROTECTION 时,出现以下错误(附图 1):Apache 检测的 Cpanel 屏幕截图

启用热链接保护时出现错误。 Apache 在重写配置中检测到错误。 AH00526:/home/…/public_html/.htaccess.9cZGH7VFKfWc6gqbrvVYVrz9qy6IaJMp 第 153 行存在语法错误: RewriteRule:错误的标志分隔符 请再试一次。

我是 WordPress 管理员,没有专业的开发人员来帮助我,所以我不知道如何解决 .htaccess 文件问题。(还附有 image2)。 .htaccess 截图

.htaccess代码(第150-155行)如下:

150: RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
151: RewriteCond %{REQUEST_FILENAME} -f [OR]
152: RewriteCond %{REQUEST_FILENAME} -d
153: RewriteRule ^ - [L]
154: RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
155: RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

有人可以帮我解决这个问题吗?

我是 WordPress 管理员,我希望 PHP 开发人员可以帮助我解决这个 Apache 错误问题。

修正:附上

.htaccess
文件

php_flag display_errors off

# BEGIN WordPress Hardening
<FilesMatch "^.*(error_log|wp-config\.php|php.ini|\.[hH][tT][aApP].*)$">
#Order deny,allow
#Deny from all
</FilesMatch>
<IfModule mod_rewrite.c>
    RewriteBase /
    RewriteRule ^wp-admin/includes/ - [F,L]
    RewriteRule !^wp-includes/ - [S=3]
    RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
    RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
    RewriteRule ^wp-includes/theme-compat/ - [F,L]
    RewriteRule ^wp-config\.php - [F,L]
    RewriteRule ^php\.ini - [F,L]
    RewriteRule \.htaccess - [F,L]
    RewriteCond %{REQUEST_METHOD} POST
    RewriteCond %{REQUEST_URI} .wp-comments-post.php*
    RewriteCond %{HTTP_REFERER} !.*myqwebsite.com.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^$
    RewriteRule (.*) - [F,L]
</IfModule>
# END WordPress Hardening
 
 
 
 
 
 
 
 
 
 
 
 
 
  
# BEGIN Gzipspeedycache
<IfModule mod_deflate.c>
    AddType x-font/woff .woff
    AddType x-font/ttf .ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/js
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE x-font/ttf
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
# END Gzipspeedycache

# BEGIN LBCspeedycache
<FilesMatch "\.(webm|ogg|mp4|ico|pdf|flv|jpg|jpeg|png|gif|webp|js|css|swf|x-html|css|xml|js|woff|woff2|otf|ttf|svg|eot)(\.gz)?$">
    <IfModule mod_expires.c>
        AddType application/font-woff2 .woff2
        AddType application/x-font-opentype .otf
        ExpiresActive On
        ExpiresDefault A0
        ExpiresByType video/webm A10368000
        ExpiresByType video/ogg A10368000
        ExpiresByType video/mp4 A10368000
        ExpiresByType image/webp A10368000
        ExpiresByType image/gif A10368000
        ExpiresByType image/png A10368000
        ExpiresByType image/jpg A10368000
        ExpiresByType image/jpeg A10368000
        ExpiresByType image/ico A10368000
        ExpiresByType image/svg+xml A10368000
        ExpiresByType text/css A10368000
        ExpiresByType text/javascript A10368000
        ExpiresByType application/javascript A10368000
        ExpiresByType application/x-javascript A10368000
        ExpiresByType application/font-woff2 A10368000
        ExpiresByType application/x-font-opentype A10368000
        ExpiresByType application/x-font-truetype A10368000
    </IfModule>
    <IfModule mod_headers.c>
        Header set Expires "max-age=A10368000, "
        Header unset ETag
        Header set Connection keep-alive
        FileETag None
    </IfModule>
</FilesMatch>
# END LBCspeedycache

# BEGIN WEBPspeedycache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_URI} \.(jpe?g|png|gif)
    RewriteCond %{DOCUMENT_ROOT}/$1.webp -f [or]
    RewriteCond /home/henryluc/public_html/$1.webp -f
    RewriteRule (?i)(.*)(\.jpe?g|\.png|\.gif)$ /$1.webp [T=image/webp,E=EXISTING:1,L]
</IfModule>
<IfModule mod_headers.c>
    Header append Vary Accept env=REDIRECT_accept
</IfModule>
AddType image/webp .webp
# END WEBPspeedycache
 
 
 
 
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat - [F,L]

### marker CACHE RESOURCE start ###
RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600]
### marker CACHE RESOURCE end ###

### marker FAVICON start ###
RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400]
### marker FAVICON end ###

### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS end ###

</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN NON_LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END NON_LSCACHE
RewriteEngine on
RewriteCond ${LeechProtect:/home/henryluc/public_html:%{REMOTE_USER}:%{REMOTE_ADDR}:4:AuNGUPpPBWWYMt7ibHx8Job4djzvzd9N} leech
RewriteRule .* /RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# SOFTACULOUS Block xmlrpc
<files xmlrpc.php>
    Require all denied
</files>
# SOFTACULOUS Block xmlrpc End
# SOFTACULOUS Block .htaccess and .htpasswd
<FilesMatch ^(?i:\.ht.*)$>
    Require all denied
</FilesMatch>
# SOFTACULOUS Block .htaccess and .htpasswd End
# SOFTACULOUS Block author scans
RewriteBase /
RewriteCond %{QUERY_STRING} (author=\d+) [NC]
RewriteRule .* - [F]
# SOFTACULOUS Block author scans End
# SOFTACULOUS Block directory browsing
Options -Indexes
# SOFTACULOUS Block directory browsing End
# SOFTACULOUS Block access sensitive files
<FilesMatch "^.*(((?:wp-config)\.(?:php|bak|swp))|php.ini|.[hH][tT][aApP].*|((?:error_log|readme|license|changelog|-config|-sample)\.(?:php|md|log|txt|htm|html)))$">
    Require all denied
</FilesMatch>
# SOFTACULOUS Block access sensitive files End
# SOFTACULOUS Enable bot protection
RewriteCond %{HTTP_USER_AGENT} (?:virusbot|spambot|evilbot|acunetix|BLEXBot|domaincrawler\.com|LinkpadBot|MJ12bot/v|majestic12\.co\.uk|AhrefsBot|TwengaBot|SemrushBot|nikto|winhttp|Xenu\s+Link\s+Sleuth|Baiduspider|HTTrack|clshttp|harvest|extract|grab|miner|python-requests) [NC]
RewriteRule ^(.*)$ http://no.access/
# SOFTACULOUS Enable bot protection End
RewriteCond %{HTTP_REFERER} !^http://myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://myqwebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://myqwebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://myqwebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://myqwebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myqwebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://myqwebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsite.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsite.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://mywebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.myqwebsites.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsite.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsite.com.myqwebsite.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsites.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsites.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsites.com.myqwebsite.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mywebsites.com.myqwebsite.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|svg)$ (.*) [R,NC]

# Wordfence WAF
<IfModule LiteSpeed>
php_value auto_prepend_file '/home/henryluc/public_html/wordfence-waf.php'
</IfModule>
<IfModule lsapi_module>
php_value auto_prepend_file '/home/henryluc/public_html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
</IfModule>
</Files>

# END Wordfence WAF

php wordpress apache .htaccess hotlinking
1个回答
0
投票

有问题的线路可能是:

RewriteRule .*\.(jpg|jpeg|gif|png|bmp|svg)$ (.*) [R,NC]

这条线的问题:

不应该出现的额外括号 (.*)。

要解决此问题,我建议您修改此行如下:

RewriteRule .*\.(jpg|jpeg|gif|png|bmp|svg)$ - [F,NC]

此更改会导致未经授权的图像文件请求为 403(禁止)。

© www.soinside.com 2019 - 2024. All rights reserved.