Hai Tien
Hai Tien

Reputation: 3117

Protect sub-directory Wordpress with htpassword return page not found

I followed this instruction to protect subdirectory. 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

Changed to

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress

It can protect sub-directory in Wordpress without returning to 404 page but It seems that the website link is not valid.

Example. Website returns error page is it does not have slash at the end of domain.

Working domain: http://demodomain.com/something/

Not working domain: http://demodomain.com/something

Upvotes: 0

Views: 42

Answers (1)

Nisarg
Nisarg

Reputation: 1641

try the following optionsrule just below RewriteEngine On:

1) RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

2) #Removing trailing slash
   RewriteRule ^(.*)/$ /$1 [L,R]

Add slash at the end of URL

RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

Or Do Following

# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

Upvotes: 1

Related Questions