Forum Moderators: phranque
The short of it is that I want to be able to have
domain.com/user
translated into
domain.com/user.php?u=id
Here is my current attempt:
RewriteRule ^([^/.]+)\/*$ user.php?u=${user_ids:${lowercase:$1}¦0} [L]
It works 100% fine except that if the username contains a . it doesn't work (gets a file cannot be displayed).
This is my last rule so basically if there is anything after the url i am going to assume that it is a user and redirect there (i would have previously processed it earlier if not).
Any thoughts?
Thanks!
I would suggest using a "positive-match" approach, allowing only alphanumeric characters, plus hyphen and periods within usernames, and using [NC] to make the pattern case-insensitive for efficiency:
RewriteRule ^([a-z][a-z0-9.\-]*[a-z0-9])$ /user.php?u=${user_ids:${lowercase:$1}¦0} [NC,L]
As coded, the pattern requires at least a two-character username. To require at least three characters, change the "*" on the middle sub-pattern to a "+". If you want to require more, use the "{min,max}" regex quantifier notation, e.g. "{2,4}" for four to six (total) characters, or "{3,}" to require at least 5 total characters, but set no upper bound.
This code --as in your example-- is intended for use in .htaccess (but note that the RewriteMap must be defined in httpd.conf or conf.d).
Jim
My problem is that user name's were allowed to be chosen prior to the "switch" so there is no criteria for what they contain.
Basically if it has gotten to this rule then if there is anything after the domain (after the first /) then I am going to assume it is a user and will lookup accordingly.
The code that I had before this one worked as well, but it required an end /. So if there is anything after www.webmasterworld.com/ then we want it to rewriterule it. Maybe I need to do some sort of rewrite condition first to see if there is something there, then if there is, run the rule?
I am surprised I made it this far and at this point I am just nit picking having to have the trailing / after a user name (I want to make it optional).
Thanks for the help!
It can only process IF there is something after the first /
I think that is why the original example I posted does work because it says to ignore the . (which index.* contains)