Wednesday, March 4, 2009

Problems with 404 error, Query string, ASP and international (Hebrew) characters

EDIT: Fixed a typo in the code where I had "QUERY_STRING" instead of "HTTP_URL"

Today I had to move a website for a client. The website is very old, and is written in ASP, and was hosted on a shared host.

The former developer wanted to have SEO friendly URLs but didn't have a URL Rewrite module available.

What he did was making a custom 404 error page, that would redirect the SEO URL and take care of the error if the URL shouldn't be redirected. As part of the script, he took the QUERY_STRING and processed it like so:

Urlstring = Request.ServerVariables("QUERY_STRING")

Response.Write UrlString
Response.Write URLDecode( UrlString )

Long story short, when moved, this code started to result in a very weird behavior. The QUERY string of international URL's turned to "???" question marks. After checking the settings for IIS, and making sure all the correct code pages are set, I found out that the behavior is changing depending if the text was before or after the '?' in the URL.

For instance, the following URL:

If you replaced 'something.asp' with international characters, they would turn to question marks, but if you replaced 'something=something' with international characters they would display properly.

After some trial and error the solution was to use "HTTP_URL" instead of "QUERY_STRING" and strip out a part of it, like so:

Urlstring = Request.ServerVariables("HTTP_URL")

Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "\/err404\.asp\?"
.IgnoreCase = True
.Global = True
End With
UrlString = RegularExpressionObject.Replace(UrlString, "")
Set RegularExpressionObject = nothing

Response.Write UrlString
Response.Write URLDecode( UrlString )

Of course, this is just a quick and dirty RegExp example, and I wouldn't advise using RegExp because they're expensive on memory and resources, but I think you're good to go from here.

Any other ideas? Feel welcome to ask questions or comment!


Anonymous said...

I have the same problem but I use Javascript. I tried your solution by using decodeURIComponent but... nothing to do... same problem

Danny.P said...

That's weird. What do you get as the HTTP_URL, and what do you get as QUERY_STRING?

AbrahamNee said...

KK777一夜激情聊天live show成人自拍貼圖自慰少婦自拍裸體圖片台灣色情成人網站情人視訊網情色留言板視訊美女免費視訊聊天室限制級極度震撼情色論壇色情特區自拍裸女貼圖潮吹性影片觀賞小穴情色片a圖片sex story性愛影片美女做愛成人色情網站性愛圖片成人情色貼圖全裸寫真集圖片走光圖女生陰毛自慰影片色情av1007成人色情聊天室女生自慰裸體照成人影音聊天台灣色情網站色情片打手槍情色天堂成人視訊聊天免費情色網站av網超性感辣妹激突成人論壇情色視訊聊天鹹濕成人網站av成人論壇免費美女視訊

עידו said...

Hi danny, I tried your solution and nothing is working. I'm on this for two weeks now and I'm desperate.

Please help me if you can...

Maybe it's something in my iis configuration. I installed hebrew on my server and still, nothing.

custom essays said...

Interesting and informative information.I am very happy to see this type article.Thank you for your great sharing.

Katherine Hayden said...

I have same while using Javascript. Anyways I got some useful information from this website. Hoping more useful post from you.