Welcome Guest, Not a member yet? Register   Sign In
Allow urlencoded string in URI
#1

[eluser]erik.brannstrom[/eluser]
Hi!

I'm using the URI to pass arguments that can basically be any possible string (it's band names and album titles) and I use urlencode to make these strings URI-friendly. I also added a plus-sign to make the permitted_uri_chars look like this:
Code:
$config['permitted_uri_chars'] = '+a-z 0-9~%.:_\-';
Now it all works fine with escaped spaces (i.e. +) but not with an ascii converted character like & (&). When such characters are used I get "The URI you submitted has disallowed characters."

Has anyone dealt with this before?

Thanks!
Erik
#2

[eluser]Maxximus[/eluser]
Hi,

I think this one will work:

Code:
$config['permitted_uri_chars'] = 'éôèüö&, a-z 0-9~%.:;_-';

Make sure your app is using UTF-8. Perhaps you need to add some other special chars as well. The ; is a tricky one, you can leave it out if you don't use things like
Code:
€
in the uri.
#3

[eluser]erik.brannstrom[/eluser]
Nope, unfortunately that config string doesn't work either.. And all pages are UTF-8.

What I have found while debugging is that CI seems to urldecode the URI before I can get to it in my method, which obviously sucks for me. Is there anyway around this? I would really like to keep the URI humanly readable, so no Base64 or database storing with hashed identifiers.
#4

[eluser]Maxximus[/eluser]
Something like /info/test-&-trick-ë.html works for me with the above config string. Could you post one of your failing URI's?
#5

[eluser]erik.brannstrom[/eluser]
For example /music/artist/Sigur+Rós, which to me looks entirely legit, returns the "The URI you submitted has disallowed characters" message. It works just fine using Sigur+Ros, and % should be an allowed charachter, so the only thing I can think of is that somewhere along the road, the ó gets decoded to ó.
#6

[eluser]Maxximus[/eluser]
Well, the + sign and ó is not in the allowed character list, so the message is right. Could you try to add the ó to the string, eg:
Code:
$config['permitted_uri_chars'] = 'óéôèüö&, a-z 0-9~%.:;_-';

and use /music/artist/Sigur-Rós?
#7

[eluser]Hannes Nevalainen[/eluser]
Code:
/music/artist/sigur_ros

or

/music/artist/sigur-ros

or

/music/artist/Sigur_Ros
I think it would be better than allow foreign characters in the url.

Happy Coding!

//En svenne till ^^
#8

[eluser]xwero[/eluser]
It's a struggle every developer has to go through when (s)he has to deal with languages that has characters that are not in the standard ascii table, how far are you willing to go make a compromise? Hannes way is the quick way out, although underscores should be avoided because search engines see it as one word AFAIK.

If you want to use a plus sign you should use it as your default space sign otherwise people will enter wrong urls. Because the rest of the url is lowercase i think the artist name should be in lowercase too. Consistency is very important in urls because the first thing people get annoyed by is wrong urls.
#9

[eluser]Hannes Nevalainen[/eluser]
[quote author="xwero" date="1218119639" although underscores should be avoided because search engines see it as one word AFAIK.[/quote]

Did not know that, these forums is great for learning.

//Thanks.
#10

[eluser]erik.brannstrom[/eluser]
Sorry, I was in a hurry and didn't notice that the string was displayed decoded.

Code:
music/artist/Sigur+R% C3% B3s (without the spaces)

is what it should look like. Now it doesn't contain any foreign characters, right?




Theme © iAndrew 2016 - Forum software by © MyBB