June 17, 2004

Url rewrite and Url Encoding::[Blog]


Liang

For the Design of Booso.com, fix several problems whit the help of Nio and Chedong,
Url rewrite:
Design the link of this kind:
http://booso.com/cgi-bin/booso.cgi?gmail to http://booso.com/gmail
and keep all the others as usural:

RewriteEngine On
RewriteRule !^/$ - [C]
RewriteRule !^/index.html$ - [C]
RewriteRule !^/archives/howto.html$ - [C]
RewriteRule !^/img/.* - [C]
RewriteRule !^/cgi\-bin.* - [C]
RewriteRule ^/?(.*) /usr/local/apache2/cgi-bin/booso.cgi?link=$1
RewriteLogLevel 9

Options ExecCGI
AddHandler cgi-script .cgi

And this will work.

After that I found that the query name in Chinese will not work under Internet Explore but works find under mozilla and conqueror. Chedong suggest fix the problem of Url encoding.

Url encoding:
In Cgi:
use CGI ();
NewQuery=CGI::escape($URL);
This will work.

For other system, Php:

PHP Example:


<?
$Text = "foo<b>bar";
$URL = "foo<b>bar.html";
echo HTMLSpecialChars($Text), "<BR>";
echo "<A HREF=\"", rawurlencode($URL), "\">link</A>";
?>


Note that PHP also has a strip_tags() function that will remove all
HTML tags from a string. Using this function in a manner such as:


echo strip_tags($Text);

will strip all HTML from the input. However, if you use it in the form:


echo strip_tags($Text, "<B>");

which only allows the "<B>" tag through, you are still often
vulnerable to users inserting script code. By design, this function
does not strip attributes from the tags. This means it is often
possible to include things such as JavaScript event attributes.
An example of a tag that would be allowed by the above strip_tags()
call is:



<B onmouseover="document.location='http://www.cert.org/'">

Some clients accept such attributes on tags that are otherwise benign.

Apache Module Example:


char *Text = "foo<b>bar";
char *URL = "foo<b>bar.html";
ap_rvputs(r, ap_escape_html(r->pool, Text), "<BR>", NULL);
ap_rvputs(r, "<A HREF=\"", ap_escape_uri(r->pool, URL), "\">link</A>", NULL);

mod_perl Example:


$Text = "foo<b>bar";
$URL = "foo<b>bar.html";
$r->print(Apache::Util::escape_html($Text), "<BR>");
$r->print("<A HREF=\"", Apache::Util::escape_uri($URL), "\">link</A>");

This uses the same functions as in the Apache Module Example, called
from Perl instead of directly from C.

For a single code, encode url is here:
perl -p -e 's/([^\w\-\.\@])/$1 eq "\n" ? "\n":sprintf("%%%2.2x",ord($1))/eg'
decode :
perl -p -e 's/%(..)/pack("c", hex($1))/eg'


Other info:
http://www.hk8.org/old_web/linux/cgi/ch02_01.htm

Posted at June 17, 2004 03:29 PM by Liang at 03:29 PM | Comments (4) | TrackBack(0) | Booso!| Niu.la收藏!


Trackback

You can ping this entry by using http://www.wespoke.com/cgi-bin/mt/mt-tb.cgi/502

Comments

第 1 楼:

TV host Oprah Winfrey gives audience members $1,000 (526) each to donate to a charitable cause...

Posted by: Marcel Muncy at December 14, 2006 09:11 AM from 67.15.2.32

第 2 楼:

TV host Oprah Winfrey gives audience members $1,000 (526) each to donate to a charitable cause...

Posted by: Marcel Muncy at December 14, 2006 09:11 AM from 66.11.54.72

第 3 楼:

TV host Oprah Winfrey gives audience members $1,000 (526) each to donate to a charitable cause...

Posted by: Tyshawn Frias at December 27, 2006 08:49 AM from 62.150.130.26

第 4 楼:

TV host Oprah Winfrey gives audience members $1,000 (526) each to donate to a charitable cause...

Posted by: Tyshawn Frias at December 27, 2006 08:49 AM from 12.45.169.249

Post a comment

请注意,为了防止spam,您的留言必需含有中文字符!









Remember personal info?




所有发表