Encoding URLs (PHP and .htaccess)

Discussion in 'Web Design and Development' started by rendezvouscp, Jun 11, 2006.

  1. rendezvouscp macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #1
    Hello. I'm a bit puzzled at the moment with how to make accented characters in URLs work. I'm using .htaccess to pass the information in the URLs to the PHP web app, and that's all working fine. However, for translations I'd like to say something like paginá instead of just page. I already have the system in place to accept translations, so that's not a problem.

    I'm fairly familiar with encoding characters with UTF-8 on a web page, but am puzzled when it comes to orchestrating URLs. Does anyone have a good resource to learn about it, or perhaps they know exactly what I need to do?

    Thanks in advance.
    -Chasen
     
  2. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    I'm not 100% sure what you're trying to do, but have you tried urlencode? :)
     
  3. rendezvouscp thread starter macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #3
    I've been trying to make that work, but I'm unsure what I'm doing wrong. Here's some example code (note: the code is actually spread across files, but here's a simplification):

    PHP:
    $page paginá;
    echo 
    "    <li class=\"current\"><a href=\"$root/$archives/$page/$id/\" title=\"$Page $id\">$id</a></li>\n";
    Code:
    RewriteRule ^archivos/paginá/([0-9]+)/?$ index.php?type=archivos&page=$1 [L]
    
    The first is the relevant PHP code, the second the relevant .htaccess code. Everything is being set correctly when
    PHP:
    $page page
    , since there is nothing to be encoded (and the right information is being brought in from the URL). However, with the accents, I'm being told that the requested URL was not found and the accented a is jibberish (while, if
    PHP:
    $page "pagin%E1"
    then it says that the requested URL was not found with the a accented as it should be).

    So, the whole point is that I do want to be able to pass the URL as something accented because it is much more true to the language. Hopefully, this is possible!

    Thanks in advance to anyone that can give me pointers on how to use urlencode properly as well (I've tried
    PHP:
    echo "    <li class=\"current\"><a href=\"$root/$archives/" urlencode($page) . "/$id/\" 
    ).
    -Chasen
     
  4. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #4
    Not sure if this will help. read up on it on php.net.

    PHP:
    \
          
    //default to UTF-8 change it ISO-8859-1
          //php defaults to ISO-8859-1
          //I think this only works for php 4 and up
           
          
    $this->charset "utf-8";   //defaults to utf-8         


                    
          
    iconv_set_encoding("internal_encoding"$this->feed->charset);
          
    iconv_set_encoding("output_encoding"$this->feed->charset);
          
    iconv_set_encoding("input_encoding"$this->feed->charset); 
        
          
     
  5. rendezvouscp thread starter macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #5
    Alrighty, I'm thoroughly confused about the subject. I'll probably sleep on the issue for the next week and see if I can't figure it out. When I figure out the solution, I'll be sure to post it back here for anyone else to enjoy.
    -Chasen
     
  6. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #6

    it is confusing... all i was saying was, you need to make sure php is going to output in utf. It doesn't default output in utf, so that might be the source of your problems.
     

Share This Page