Help me with regular expressions please!

Tags: ,

It seems I am too dumb to understand how this works.. no matter how many tutorials I read, I’m still not able to produce something that is working.. I suck :D

So what I would like to do is this: I have a domain and I would like that everything that comes after it and is not preceded by a ?get value is automatically a nickname and goes to ?user=$1.

What I have now is this:
RewriteRule ^(.*)$1 [L,nc]
RewriteRule ^([\w-]+)$ ?user=$1

I don’t understand why I need two lines but one without the other doesn’t work. And there is more, this works almost fine, except that it works only with letters and numbers but doesn’t include any special char (like for example a dot .) and that’s because of the \w which gets letters and numbers. But how do I include \W ? If I put [\w\W] I get an internal server error.. I’ve run out of ideas.

And something more.. if I rewrite my urls like this (this is another project):

RewriteRule ^artist/(.*)$ ?band=$1

do I need to change all my urls from relative to absolute (from ?something to Is there any way to make it another way?

And if you have any super easy regular expressions for dummies, please share it :D

Thank you!

If you liked this post think about subscribing to my RSS feed and prevent missing anything interesting. It's free, fast and doesn't hurt. Promise. Click here.
Related posts: