4

My htaccess rewrite must handle these scenarios:

My current .htaccess configuration is:

RewriteRule ^dictionary/([\w\+]{2,50})$ /words.php?q=$1 [QSA,L]

It is not recognizing the special chars, e.g.: ñ, ó.

Any ideas? Thanks!

Andres SK
  • 10,779
  • 25
  • 90
  • 152

3 Answers3

6

Final solution

RewriteRule ^dictionary/([^/.]+)$ /words.php?q=$1 [QSA,L]
Andres SK
  • 10,779
  • 25
  • 90
  • 152
1

Add a % to the character class in your expression:

RewriteRule ^dictionary/([\w+%]{2,50})$ /words.php?q=$1 [QSA,L]

Or you could even use [^/]{2,50}.

Special (something like [^A-Za-z0-9_]) characters are encoded by the client upon request. Note that åäö would become 9 characters, and even a single å would pass trough this expression. If you want to allow 50 special chars, use {2,150} and check both side of the range in your PHP code after decoding the string (which I guess is done for you automatically).

Qtax
  • 33,241
  • 9
  • 83
  • 121
0

Its better to convert the string into default url encode mechanism. AFAIK the request to url#1 cannot be made without encoding the url. Also the decoding would be done on the server side so you need not worry about that. If you are using some framework or server side script I would suggest to pass the pantalón via POST rather than get.

You can use jquery post http://api.jquery.com/jQuery.post/

If you still want to go through GET :

How to handle special characters in .htaccess rules?

Also be aware that the URLs will get encoded.

Community
  • 1
  • 1
Gaurav Shah
  • 5,223
  • 7
  • 43
  • 71
  • it must be done through GET because it must be a reachable url. So, what would be the best for the htaccess to accept the % and + characters as well? – Andres SK Nov 30 '11 at 05:55