You can use the R
flag on the RewriteRule
to force a redirect with a given status code:
While this is typically used for redirects, any valid status code can be given here. If the status code is outside the redirect range (300-399), then the Substitution string is dropped and rewriting is stopped as if the L flag was used.
So this:
RewriteRule ^/?page\.html$ - [R=404]
would return the default 404 page for /page.html
. Since this is a regexp, remember the escaping \.
and anchoring $
.
-
is ignored (i.e. “the Substitution string is dropped”), but there still needs to be something there to keep the rule well-formed.