.htaccess 404页面不存在404页面不存在

niwlg2el  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(179)

我在www.example.com安装了一个WordPressmydomain.com/blogs,并且我有以下.htaccess

RewriteEngine On
RewriteBase /blogs/
RewriteBase /
RewriteRule ^index\.php$ - [L]
ErrorDocument 404 /blogs/

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

#RewriteBase /
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [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]

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogs/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogs/index.php [L]
</IfModule>

# END WordPress

现在一切正常,但像
mydomain.com/blogs/wp-content/plugins/
mydomain.com/blogs/wp-config.php
没有被正确地重定向到404。它显示一个空白的白色页面。我需要这些文件被重定向到404页面。请帮助。

z5btuh9x

z5btuh9x1#

使用您显示示例和尝试,请尝试以下.htaccess规则文件除了添加新规则外,还在现有规则中添加了一些标志
请确保在测试URL之前清除浏览器缓存。

RewriteEngine On
RewriteBase /blogs/
RewriteBase /
RewriteRule ^index\.php$ - [NC,L]
ErrorDocument 404 /blogs/

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,NC,L]

#RewriteBase /
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [NC,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [NC,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [NC,L]
RewriteRule ./index.php [NC,L]

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteBase /blogs/
RewriteRule ^index\.php$ - [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/blogs/wp-content/plugins/?\s [NC]
RewriteRule . /blogs/index.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/blogs/wp-config\.php(\?\S+)?\s [NC]
RewriteRule . /blogs/index.php [NC,L]
</IfModule>

# END WordPress
vecaoik1

vecaoik12#

您可以强制进行404重定向:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ^/wp-config\.php$
RewriteRule .* - [L,R=404]

相关问题