1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

banning nonenglish characters in url

Discussion in 'Web Design' started by revekozu, Mar 3, 2012.

  1. revekozu

    revekozu Junior Member

    Joined:
    Jul 30, 2010
    Messages:
    133
    Likes Received:
    41
    First off. No offense to our non English speaking friends. I just can't monetize this traffic and also fear an adsense ban for the site.

    The site uses a search parameter at the end of certain urls an gradually it has been flooded with foreign language searches. I don't wan to do country bans by ip. But maybe limiting the unicode charset somehow via htaccess could work.

    or here is the start of a different solution using htacess

    Code:
    RewriteEngine On
    
    # Block access when 'ஷ்' in url
    
    RewriteCond %{REQUEST_URI} .*ஷ்.* [NC]
    RewriteRule ^(.*)$ $1 [F,L]
    and this works when that character is in a searched word. I'm tempted to ask how to put more characters from words in my logfiles like that in an array. But surely there is a better way to exclude characters beyond the range 0-127?


    (I really suck at figuring out htaccess and always end up begging for help somewhere... but hopefully others learn from my questions)
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,155
    This regex matches non-english characters. mod_rewrite uses regular expressions, so...

     
    • Thanks Thanks x 1
  3. revekozu

    revekozu Junior Member

    Joined:
    Jul 30, 2010
    Messages:
    133
    Likes Received:
    41
    Cool. Can't wait to try it. Well actually I do have to wait...things to do...but asap.
     
  4. revekozu

    revekozu Junior Member

    Joined:
    Jul 30, 2010
    Messages:
    133
    Likes Received:
    41
    Works like a charm. Decided to redirect to home page. May as well keep any link juice.

    Final code for any one else.

    Code:
    RewriteEngine On
    
    # Redirect access when '[^\x00-\x80]+' in string
    
    
    RewriteCond %{REQUEST_URI} .*[^\x00-\x80]+.* [NC]
    RewriteRule ^/* http://www.mysite.net/ [L]
     
    Last edited: Mar 7, 2012