简体   繁体   English

.htaccess 在 Wordpress 中导致 403 Access Denied

[英].htaccess causing 403 Access Denied in Wordpress

I have a website for eg.我有一个网站,例如。 www.example.com which has a custom .htaccess file designed to increase the site speed and make sure that the directory can't be listed. www.example.com 有一个自定义的 .htaccess 文件,旨在提高站点速度并确保无法列出目录。

I have a WordPress installed in the /blog directory ie;我在 /blog 目录中安装了一个 WordPress,即; www.example.com/blog/, the blog was working fine till the updated version of the website while after a span of a week the blog stops opening and started showing 403 Access denied. www.example.com/blog/,该博客在网站更新版本之前运行良好,而一周后博客停止打开并开始显示 403 访问被拒绝。 Tried every method available on google I went to the second page of google too .尝试了谷歌上所有可用的方法我也去了谷歌的第二页

After an hour I removed the .htaccess of the base directory and my blog is running up and fine again, I was a little curious to know if I will place the .htaccess file again what will happen and after I pushed it back to the server nothing happens to the WordPress site.一个小时后,我删除了基本目录的 .htaccess 并且我的博客再次运行并恢复正常,我有点想知道我是否会再次放置 .htaccess 文件会发生什么,在我将它推回服务器之后会发生什么WordPress 网站没有任何反应。

But I am afraid this can happen in the near future and hence I need to find out what part of my .htaccess is causing this problem.但我担心这会在不久的将来发生,因此我需要找出我的 .htaccess 的哪一部分导致了这个问题。 I still can't access wp-admin.我仍然无法访问 wp-admin。

在此处输入图片说明

My .htaccess code:我的 .htaccess 代码:

ErrorDocument 404 https://example.com/Error
ErrorDocument 500 https://example.com/Error
ErrorDocument 401 https://example.com/Error

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

# START DEFLATE COMPRESSION
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font" \
"application/x-font-opentype" \
"application/x-font-otf" \
"application/x-font-truetype" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/otf" \
"font/ttf" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
# END DEFLATE COMPRESSION

# START ENABLE KEEP ALIVE
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
# END ENABLE KEEP ALIVE

# START EXPIRES CACHING #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresDefault "access 1 month"
</IfModule>
# END EXPIRES CACHING #


# DISABLE IMAGE HOTLINKIING START
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
# DISABLE IMAGE HOTLINKIING END

# ENABLE MOD PAGESPEED START
# COMBINE CSS, COMPRESS IMAGES, REMOVE HTML WHITE SPACE AND COMMENTS
<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters rewrite_css,combine_css
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>
# ENABLE MOD PAGESPEED END

# START – Disable server signature #
ServerSignature Off
# END – Disable server signature #

# ENABLE LITESPEED CACHE START
<IfModule LiteSpeed>
CacheEnable public
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET|HEAD$
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{REQUEST_URI} !login|admin|register|post|cron
RewriteCond %{QUERY_STRING} !nocache
RewriteRule .* - [E=Cache-Control:max-age=300]
</IfModule>
# ENABLE LITESPEED CACHE END

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

#Alternate default index page
DirectoryIndex Home.html

Well there is a small mistake from my side in the end好吧,我这边最后有一个小错误

#Alternate default index page
DirectoryIndex Home.html

This code makes Home.html the default homepage of every directory and I haven't declared default page in the .htaccess file of WordPress, which is finding Home.html and as SecuPress is enabled he is blocking this request so I just added this code to .htaccess of WordPress folder此代码使 Home.html 成为每个目录的默认主页,并且我没有在 WordPress 的 .htaccess 文件中声明默认页面,该文件正在查找 Home.html 并且启用 SecuPress 后他阻止了此请求,因此我刚刚添加了此代码到 .htaccess 的 WordPress 文件夹

#Alternate default index page
DirectoryIndex index.php

and everything worked fine as expected.一切都按预期工作。 But I lost my WordPress theme and Plugins setting while finding this.SED.但是我在找到 this.SED 时丢失了我的 WordPress 主题和插件设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM