开发者

RewriteRule .? only for one or more chars?

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 o开发者_如何学编程n 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.


I haven't tested, but I think this will redirect absolutely any request to 404.php.

The regex .? will search for 0 or 1 character, any character, at any position of the url. So basically, any url will match the first regex and will redirect.

The [L] at the end of the line makes mod-rewrite to not process any more rules when it founds a match.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜