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

[eluser]Maxximus[/eluser]
Why would you want to do that? It will kill your SEO. Nobody will ever type that in a searchengine. Nor a plus sign.

I would say this works out best for SEO:
Code:
music/artist/sigur-rós.html
Since your users will use an ó and not o in the 'rós' part. Since u are using UTF-8 there is no reason to use urlencoding I think.

You will probably do a db lookup with the above string. In my app I replace all non-ASCII chars with a question mark, that way it will also find 'sigur ros' (but 'sigur rus' too).

I make sure my db search is in lower case too, so it will make no difference if someone is using uppercase/lowercase mix.
#12

[eluser]erik.brannstrom[/eluser]
Thanks for your answers!

Hm, SEO hadn't even entered my mind. But honestly, for this function it is not a high priority. The parameter is more of a search term than anything else. The process of making every possible artist name SEO friendly seems to be a process I'd rather not go through..

For example, turning spaces into dashes will be a problem when I'm turning them back to spaces for the DB query. A band such as Hard-Fi would therfore not return the exact matches I'm looking for.

Maybe I could make a DB table that carries SEO versions of every artist. It seems kind of inconvenient, but maybe it's the best solution. Or are there any other suggestions?

By the way, regarding the question if CI is urldecoding the URI, it seems it is in fact mod_rewrite that does the decoding. This is at least what I have found while googling. Should be possible to circumvent by double encoding, but for some reason it fails me..

Oh, and Hannes.. Skönt att veta att det finns fler Smile
#13

[eluser]Colin Williams[/eluser]
You always have the option to override the necessary methods in the URI class by creating an application/libraries/MY_Uri.php file. But these guys are right, people won't type in the character entities, or even the proper character, when typing it out by hand. What you need to do is have a process that rewrites all non-ascii chars into ascii chars before URI class tries to validate it.. I believe this is what some other frameworks/CMSs do
#14

[eluser]Unknown[/eluser]
Check this out...

A small patch in URI lib. could allow anyone to safely allow some UTF-8 chars to their stuff:

Here's the stuff:

How to put UTF-8 characters in your uri string ?
As a romanian I had to do this...

1) You just create a MY_URI.php in your application/libraries folder.
2) You open this up: http://webdesign.about.com/od/localizati...des-ro.htm to get the special characters ascii codes. Those are for romanian language but you should look up your language as well.
3) You put this code in the MY_URI.php file you just created:

Code:
<?php
class MY_URI extends CI_URI {

    function _filter_uri($str)
    {
        if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
        {
            // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
            // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
            if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')) . $this->config->item('utf_uri_chars') . "]+$|i", $str))
            {
                show_error('The URI you submitted has disallowed characters.', 400);
            }
        }

        // Convert programatic characters to entities
        $bad    = array('$',        '(',        ')',        '(',      ')');
        $good   = array('$',    '(',    ')',    '(',    ')');

        return str_replace($bad, $good, $str);
    }
}
?>

4) You add this to your config/config.php file to allow Romanian special chars:
Code:
$config['utf_uri_chars'] = '\xDB\x102\x103\xC2\xE2\xCE\xEE\xDA\x15E\x15F\x21A\x21B\x162\x163';
5) Replace those codes with the ones you need to allow in your own language if it's not Romanian, all though in a few years, after we'll conquer the world, we'll all speak Romanian.... SO I guess you could also use those... Just to be prepared for the long-run...
6) That's it.
7) Enjoy
8) ............
#15

[eluser]Unknown[/eluser]
thanks ... that was usefull




Theme © iAndrew 2016 - Forum software by © MyBB