.htaccess rewrite rule puzzle

Because I need to password protect a subdirectory using cPanel, I modified WordPress’s .htaccess rule as instructed here: https://wordpress.org/support/topic/password-protect-a-directory-with-htaccess

This is my current wordpress rewrite block:

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

# END WordPress

Notice particularly this line:

RewriteRule ./ /index.php [L]

The normal wordpress Rewrite Rule is this:

RewriteRule . /index.php [L]

It works perfectly for the password-protected directory. But I seem to have lost the rewrite for when a page gets loaded without the trailing slash.

Before I changed this, WordPress would look at a url like this:
http://example.com/about-us and load it up as http://example.com/about-us/ (with a trailing slash).

Now it simply goes to a Not Found page. It’s not even loading the theme’s 404 page.

Any ideas how to fix this without mucking up my password-protected directory?

1 Answer
1

You can use question mark:

RewriteRule ./?$ /index.php [L]

Leave a Comment