用apache 2的mod_ext_filter给html文件加广告。
用apache 2的mod_ext_filter给html文件加广告。
想在静态页面上自动加个广告条,而不必手动修改每个静态页面。
按照这个需求在google上找了一段时候,不得要领。
后来想起来tomcat里有filter的概念的。
就到apache的文档里找。
瞎猫碰到了这个死耗子。
http://httpd.apache.org/docs/2.0/mod/mod_ext_filter.html
由于自己学习不认真,并且编程能力不强,笨拙的按照文档解决了这个问题。
个人感觉就是unix管道的理念。
服务器环境是centos 4.2 /apache 2.0.52
首先加载mod_ext_filter
在/etc/httpd/conf/httpd.conf
的Dynamic Shared Object (DSO) Support节
加入
Code:
LoadModule ext_filter_module modules/mod_ext_filter.so
然后定义filter的名字(advtext)和配置filter要调用程序的名字(gingeradv)。
Code:
ExtFilterDefine advtext mode=output intype=text/html cmd="/usr/bin/gingeradv"
在Directory标签里加入如下行。
Code:
SetOutputFilter advtext
加入后看起来如下
Code:
<Directory />
Options FollowSymLinks
AllowOverride None
SetOutputFilter fixtext
</Directory>
用于加入广告的程序gingeradv是用perl写的,自己笨写的很垃圾。
Code:
#!/usr/bin/perl
my @lines = <STDIN>;
open ADVLINE, "/var/www/html/abc.txt" or die "cant't find the adv files";
my @advlines = <ADVLINE>;
print @lines,@advlines;
记得要给这个文件执行的权限。
Code:
chmod a+x gingeradv
要显示的广告保存在/var/www/html/abc.txt里。
我用于测试的这个是一个google的Google AdSense
abc.txt如下
Code:
<script type="text/j avascript"><!--
google_ad_client = "pub-5617089787488679";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/j avascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
然后重新启动apache服务器
Code:
apachectl graceful
相关文档:
一张图片不必切割成各种按钮。做前端的接触的比较少,应该虚心学习……
<img src="images/b.gif" mce_src="images/b.gif" alt="标题" width="685" height="23" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" mce_shape="rect" coords="31,1,70,20" mce_coords="3 ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
......
1 <html:html>标记
简单的在页面的开始和结尾处产生一个html标记。
2<html:base>
用于在网页的head部分生成一个base标记,作用不仅仅是生成本网页的URL ,更重要的是为该页面的所有其他的链接提供相对的位置。
3 <html:link>
用于生成html中的<a> ......
W3C标准的HTML标签
按功能类别排列
DTD:指示在哪种 XHTML 1.0 DTD 中允许该标签。
S=Strict,严格类型, T=Transitional,过渡类型【最普遍】, F=Frameset,框架类型.
标签成对,xhtml是比html更严格,类似XML格式
标签描述DTD
<!DOCTYPE>
定义文档类型。
STF
<html>
定义 HTML 文档。
STF
< ......