我遵循此指令来保护子目录。 https://support.hostgator.com/articles/wordpress-preventing-you-from-password-protecting-a-directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
更改为
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress
它可以保护Wordpress中的子目录,而无需返回404页面,但似乎该网站链接无效。
示例。网站返回错误页面,因为它的域名末尾没有斜杠。
答案 0 :(得分:1)
在RewriteEngine启用下方尝试以下选项规则:
1) RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
2) #Removing trailing slash
RewriteRule ^(.*)/$ /$1 [L,R]
在URL末尾添加斜杠
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
或执行关注
# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]