Your rules are in the wrong order. Your “Custom Redirect” needs to be at the top of the .htaccess
file before the WordPress front-controller, ie. before the # BEGIN WordPress
comment marker.
By placing it after the WordPress code block it will only get processed for requests that map directly to files and directories (including the document root, but excluding /index.php
). (Although your custom redirect actually excludes the root, by the first condition?)
UPDATE:
but
RewriteCond %{REQUEST_URI} !^/path/page-accessible/
is ignored, so the page is also redirected… ?
Well, it’s not “ignored”. However, the request is then internally rewritten to index.php
(the WP front-controller) by the later rule and it’s this that is then redirected on the second pass through the rewrite engine (which makes it look as if the above condition is being ignored).
You need to either:
-
Exclude
index.php
by adding another condtion to your rule. For example:RewriteCond %{REQUEST_URI} !^/index\.php$ :
OR,
-
Make sure the rule is only applied to direct requests from the client and not internally rewritten requests by the later rewrite. For example:
RewriteCond %{ENV:REDIRECT_STATUS} ^$ :
The
REDIRECT_STATUS
environment variable is empty on the initial request and set to “200” (as in 200 OK HTTP response status) after the later rewrite.