1

i have a problem. I hope you can help me. I don’t speak english very well, but i try to explain me good as i can.

I am from argentina, so, i have to work with the “ñ” character. For SEO, i want include the “ñ” at the url for some words, so, for example, i have:

  • Controller: webdesign.php
  • Route: $route[‘diseñoweb’] = “webdesign”;

But, when i enter to “www.domain.com/diseñoweb” it doesn’t work. And i need the “ñ” character in the url. Do somebody know how can i do this?

Thank you!

3 Answers3

3

What you want to do is most likely not going to work as you want, because URLs can't contain non-ASCII characters. See here for background.

I think you need to create a route for the URLencoded version, like so:

$route['dise%c3%b1oweb'] = "webdesign";

if you then enter a URL containing

diseñoweb

a modern browser will automatically URLencode the character.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
2

first, you need to allow that char in your config, for example you can have something like these…

$config['permitted_uri_chars'] = 'a-z 0-9_\-ñ'; 

Then, at system/core/URI.php, on line 231, replace

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) 

to

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", utf8_encode($str))) 
toopay
  • 1,635
  • 11
  • 18
  • 3
    Can i do that without hack the core files? –  Aug 21 '11 at 16:35
  • Well, you can extends the URI class, and replace/overide related function of that block. But bear in mind, that CI is really strict in their URI. As default, CI doesnt permit any "unusual" char as security reason. So if you really need to do this, the option is to modify above section. – toopay Aug 21 '11 at 16:37
  • CI probably prohibits the characters because non-ASCII characters won't work directly - see here for background [Unicode characters in URLs](http://stackoverflow.com/q/2742852) – Pekka Aug 21 '11 at 16:39
  • i combine both Pekka and toopay solution. Thanks. –  Aug 21 '11 at 16:44
2

You may try this

$route[rawurlencode('diseñoweb')] = “webdesign”;
ace
  • 7,293
  • 3
  • 23
  • 28