.htaccess - Special character friendly urls

Asked

Viewed 776 times

0

I have the following line:

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

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

How can I do?

  • Let him accept where? Together in the square brackets?

  • Anywhere if I search for J:Osi=m@r@! no error

  • Yes in the square brackets.

1 answer

1


Possible Solution

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

Notes

  • [] works as a capture by verification, "in the character I am testing 'I' I accept what possibilities?"
  • Note that you only need once the character for it to be accepted, thus the , does not need to appear several times - although I believe its purpose was to separate contents
  • In regex there is no need to separate content, it simply follows the sequence passed a-z,0-9,A-Z, = a-z0-9A-Z
  • Special characters can be taken literally through the exhaust \, \?, \+
  • Within the [] you have two means of capture literally the - having in view that he is also a special character (from, up), keeping him at the end -] or applying exhaust \-

Improving

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

Improved solution

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.