Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorverb
    • CommentTimeSep 14th 2007 edited
     permalink

    I've got the following rewrite rules in my htaccess file:

    RewriteRule ^(.*\.(jpg|gif|png|css|js))$ $1 [L]
    RewriteRule ^(.*)$ index.php?path=$1 [QSA]
    

    Normally, this wouldn't give me any problems, since my urls contain just letters, numbers and underscores (and some slashes, of course). But here it comes: my tag cloud has urls like /tag/%C3%B8%C3%AF%C3%A9+%C3%B1%2B

    Mod rewrite decodes these characters, so by the time the variable reaches the PHP code, %2B has become the same as %20, etc. If googled a bit about it, read something about a [NE] flag, but I can't get it to work (once again ;-). I found out that encoding the urls twice is a solution: urlencode(urlencode($variable)), but that would produce even dirtier urls.

    Maybe someone here can help me out?

  1.  permalink
    Am I reading this wrong, or could you fix the problem by replacing those characters (like the slashed "o") with compatible ones before they hit mod rewrite? I have to deal with this when umlauts are involved. The letter "ä" becomes an "a", "å" becomes an "o" or an "a" and so forth. Just use your string replacement function of choice. Here's an example:

    $url = str_replace('ä', 'a', $url);
    • CommentAuthorverb
    • CommentTimeSep 14th 2007 edited
     permalink
    That's one possibility, but unfortunately it only takes care of letters. How to deal with tags like 'c++' and 'H&M', for example?
  2.  permalink
    Perhaps something like "c_plusplus" or "H_and_M"? Hopefully someone else will step up soon and provide a better solution, but that's all I've got.
    • CommentAuthorverb
    • CommentTimeSep 14th 2007
     permalink
    Yeah you're right. It's a nice workaround but it would probably be better with the encoding working.
  3.  permalink
    kari.patila
    Perhaps something like "c_plusplus" or "H_and_M"? Hopefully someone else will step up soon and provide a better solution, but that's all I've got.

    Thats basically the same thing i thought of. The only thing i would add is a symbol to help prevent a possible mis-decode.. err i think that made sense.
    example:
    H&M -> H%and%M
    Jack and Jill -> Jack_and_Jill
    PHP+JS -> PHP%plus%JS
    mom_dad &kids -> mom__dad_%and%kids

    it should be easy to implement:
    $replacements = array("_","%plus%","%add%","%percent%");
    $real_text = array(" ","&","+","%");

    $url = str_replace($real_text,$replacements,$place_string_here); // encode to url
    $regular_text = str_replace($replacements,$real_text,$place_string_here); // decode back to text


    i haven't tested this but i believe it would work
Add your comments
    Username Password
  • Format comments as (Help)