Rewrite url to exclude Spanish characters

Discussion in 'Apache' started by viajeria, Jan 20, 2010.

  1. #1
    Hi,

    I've been reading various forums and I can't find exactly what I want. I'm using the Affilistore script for a price comparison site and using mod_rewrite with the following code:
    RewriteEngine On
    RewriteBase /


    #Rewrite image paths to look like jpgs
    RewriteRule ^img/([^/]+)/([^/]+)\.jpg$ imgsrc.php?proddb=$1&img=$2 [L]
    RewriteRule ^img/([^/]+)/([^/]+)/([^/]+)\.jpg$ imgsrc.php?&proddb=$1&img=$2&single=$3 [L]

    RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=product&proddb=$1&pid=$2&urltxt=$3 [L]
    RewriteRule ^saveproduct/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=product&proddb=$1&pid=$2&urltxt=$3&savelink=true [L]
    RewriteRule ^products/([^/]+)\.html$ index.php?case=products&pc=$1 [L]
    RewriteRule ^subproducts/([^/]+)/([^/]+)\.html$ index.php?case=subproducts&pc=$1&pb=$2 [L]
    RewriteRule ^productspage/([^/]+)/([^/]+)\.html$ index.php?pageNum_product=$1&case=products&pc=$2 [L]
    RewriteRule ^subproductspage/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?pageNum_product=$1&case=subproducts&pc=$2&pb=$3 [L]
    RewriteRule ^categories/([^/]+)/([^/]+)\.html$ index.php?case=categories&nc=$1&urltxt=$2 [L]
    RewriteRule ^subcategories/([^/]+)/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=subcategories&nc=$1&nb=$2&urltxt=$3&suburltxt=$4 [L]
    RewriteRule ^categoriespage/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?pageNum_product=$1&case=categories&nc=$2&urltxt=$3 [L]
    RewriteRule ^subcategoriespage/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?pageNum_product=$1&case=subcategories&nc=$2&nb=$3&urltxt=$4&suburltxt=$5 [L]
    RewriteRule ^news/([^/]+)\.html$ index.php?case=news&npag=$1 [L]
    RewriteRule ^news/([^/]+)/([^/]+)\.html$ index.php?case=news&npag=$2&npage=$1 [L]
    RewriteRule ^newsitem/([^/]+)/([^/]+)\.html$ index.php?case=newsitem&npag=$1&urltxt=$2 [L]
    RewriteRule ^links/([^/]+)\.html$ index.php?case=links&ld=$1 [L]
    RewriteRule ^linksh/([^/]+)/([^/]+)\.html$ index.php?case=links&ld=$2&lpage=$1 [L]
    RewriteRule ^links/([^/]+)/([^/]+)\.html$ index.php?case=links&ld=$1&cat=$2 [L]
    RewriteRule ^links/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=links&ld=$2&cat=$3&lpage=$1 [L]
    RewriteRule ^page/([^/]+)/([^/]+)\.html$ index.php?case=page&page=$1&urltxt=$2 [L]
    RewriteRule ^subpage/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=subpage&page=$1&subpage=$2&urltxt=$3 [L]
    RewriteRule ^stores/([^/]+)\.html$ index.php?case=stores&merchant=$1 [L]

    My site tiendapcweb.com is in Spanish, so the rewritten url's for the characters with accents and other special characters don't show properly, and this is screwing me up in Google, since they won't accept my sitemap and won't index these url's. How can I replace these special characters with "normal characters"? For example, replace "ñ" with "n", "è" with "e", etc.?

    Thanks very much for your help,

    Paul
     
    viajeria, Jan 20, 2010 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    I think it might be easier not to put the special characters into the database or to strip them when the data is read and the friendly URL is being created for the display. I am assuming that you are using a database, and a scripted solution.

    You would do that by creating an array of the special chars and then using str_replace( ) to replace them with what ever char you wanted.

    Not putting them into the database in the first place is the better choice.
     
    Colbyt, Jan 20, 2010 IP