I am writing a mod rewrite rule to allow only one period between an arbitrary length characters. The characters must begin with a letter, followed by 2-29 characters or numbers, and allow only one period (optional) somewhere in the middle (but never in the end).
Here is what I have so far:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]([.a-z0-9]{2,29}))$ user.php?u=$1 [NC,QSA,L]
This rule is not working since it allows things like f.oo (valid), foo. (invalid), f.o.o (invalid), or even f.......
Is it possible to accomplish using just apache's mod rewrite? Or does the check have to be done in PHP or somewhere else?
Similar questions: this one and this one.
Thank you.