On the net I found several ways of defining a RewriteRule like:
RewriteRule .? 404.php [L]
RewriteRule . 404.php [L]
RewriteRule ^ 404.php [L]
But why would these work when entering a garbage url? Because the first (.?)
means that there should be zero or one char which would lead to 404.php (not a whole bunch of chars or a word). Likewise, .
and ^
look only for a char and a start of a line (not a line with a few chars or words, right?), respectively. That's what I think based on the RegEx help. Am I wrong? Or ...?
They work because they probably match that “garbage URL”. Because
.?
matches zero or one characters,.
matches a single character, and^
matches just the begin of a string (no matter what follows).The question is rather, how you differentiate between “garbage” and “non-garbage” URLs.