Mod重写模式问题[重复]

Possible Duplicate:
What literal characters should be escaped in a regex?

RewriteRule ^profile/[A-Za-z_-\d\^\.]/*$ ./index.php?page=showuser&username=$1

I am new to mod rewrite. Could someone tell me what's wrong with my pattern here? I am trying to only let names passed in that have characters, numbers, -, ^, _ and . symbols but it will give me an error when I use that syntax.

4 things:

  • missing a slash at the start
  • you forgot a + after your character class :)
  • you also forgot to capture the username :p
  • you should always put the - character in caracter classes at the beginning fo the class

(also, you don't need to escape anything else than ] inside a character class)

RewriteRule ^/profile/([-A-Za-z_\d^.]+)/*$ ./index.php?page=showuser&username=$1

Try

RewriteRule ^profile/([\w\d\.^_-]+)/?$ ./index.php?page=showuser&username=$1

It might be better to use

RewriteRule ^profile/([\w\d\.^_-]+)/?$ /index.php?page=showuser&username=$1

if your index.php file is in the top (root) of your public folder.