.htaccess - Friendly URLs with special characters

0

I have the following line:

RewriteRule ^usuario\/([a-z,0-9,A-Z,._-]+)?$ index.php?pg=usuarios&usuario=$1

I needed it to accept the characters @ : = ! ?

How can I do this?

    
asked by anonymous 02.04.2016 / 00:25

1 answer

1

Possible Solution

RewriteRule ^usuario\/([a-z,0-9,A-Z,._@:=!\?-]+)?$ index.php?pg=usuarios&usuario=$1

Notes

  • [] works as a catch per scan, "in the character I'm testing, do I accept what possibilities?"
  • Note that you only need the character once for it to be accepted, so , does not need to appear several times - although I believe its intent was to separate contents
  • In regex there is no need to separate content, it simply follows the last sequence a-z,0-9,A-Z, = a-z0-9A-Z
  • Special characters can be literally taken through escape \ , \? , \+
  • Within [] you have two means of capturing literally - having in mind that it is also a special character (from, to), holding it at the end -] or applying escape \-

Improvement

  • Note that in the brackets you have a-zA-Z0-9_ which is just the anchor \w

Improved solution

RewriteRule ^usuario\/([\w,.@:=!\?-]+)?$ index.php?pg=usuarios&usuario=$1
    
02.04.2016 / 12:24