Page is a not externally linkable
lucy24 - 10:11 pm on Jun 23, 2012 (gmt 0)
I need a 404 to be returned when just 'www.domain.com' is enterered on its own as well.
The .* in g1's example will take care of that. It means "the request is for something or nothing". Yes, there is a difference between a null request and no request ;)
If someone types or clicks "www.example.com" their own browser will append a trailing slash, so it reaches the server as "www.example.com/". (Only with bare domain names! Other trailing-slash redirects happen on site.)
All RewriteRules ignore "www.example.com/" so what's left over is, by definition, .* Since you are serving up a [G] you don't need the capturing parentheses. You only need the RewriteCond to check for {HTTP_HOST}
If these requests are only coming in for pages or directories-- that is, nobody asks for pictures etc with the wrong domain name-- you can constrain the rule a little further by writing it so it only applies to trailing / or .html.
Caution! If you do this, you need to write a second Condition, either making an exception for "my410.html" or limiting the rule to {THE_REQUEST}, because you will otherwise get into an infinite loop. Something analogous happened to me not long ago with a custom 403 page.
Is there really such a thing as [R=404]?
If you decide to go the 410 route, make sure you have a nice 410 page-- or simply use your custom 404 page for both. The built-in 410 page is scary.