apache note | Apache 学习笔记(心得) by Emerald 绿色学院 - Green Institute[5]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 btbtd 的 blog

务器中的规则集。 # 对一个特定的规则集应该首先去理解而后再去用以避免出问题。 # 重写语法 # rewriteengine on # rewriterule ^/$ /www/ [r] # 一般重写方法 # 重写页面:http://gi.2288.org:88/modules/news/index.php  # rewriterule /modules/news/index.htm$ /modules/news/index.php # 完成页面: http://gi.2288.org:88/modules/news/index.htm # 重写页面: http://gi.2288.org:88/modules/news/index.php?storytopic=2 # rewriterule /modules/news/topic_(.*)\.htm$ /modules/news/index.php?storytopic=$1 # 完成页面: http://gi.2288.org:88/modules/news/topic_2.htm # 重写页面:http://gi.2288.org:88/index.php?storytopic=2start=10 # rewriterule /topic(.*)-(.*)\.htm$ /index.php?storytopic=$1&start=$2 # 完成页面: http://gi.2288.org:88/topic2-2.htm # 注: 每增加一个重写id,必须累加$1 # 比如页面: http://gi.2288.org:88/ct=2x=10y=20 # 可以这样重写: # rewriterule /ct(.*)-(.*)-(.*)\.htm$ /ct=$1x=$2y=$3 # 效果: http://gi.2288.org:88/ct2-10-20.htm # 移动宿主目录到不同的网站服务器 # 说明: # 通常,许多网管在建立一个新的网站服务器时,都会有这样的要求: # 重定向一个网站服务器上的所有宿主目录到另一个网站服务器 # 方案: # 很简单,用mod_rewrite。在老的网站服务器上重定向所有的url # /~user/anypath到http://newserver/~user/anypath。 # rewriteengine on # rewriterule ^/~(.+) http://newserver/~$1 [r,l] # 依赖于浏览器的内容 # 说明: # 至少对重要的顶级页面,有时候有必要提供依赖于浏览器的最佳的内容, # 即对最新的netscape提供最大化的版本,对lynx提供最小化的版本, # 而对其他的浏览器则提供一个功能一般的版本。 # 方案: # 对此,内容协商无能为力,因为浏览器不提供其那种形式的类型, # 所以只能在http头"user-agent"上想办法。 # 以下规则集可以完成这个操作: # 如果http头"user-agent"以"mozilla/3"开头, # 则页面foo.html 被重写为foo.ns.html ,而后重写操作终止; # 如果是"lynx"或者版本号为1和2的"mozilla",则重写为foo.20.html ; # 而其他所有的浏览器收到的页面则是foo.32.html : # rewritecond %{http_user_agent} ^mozilla/3.* # rewriterule ^foo\.html$ foo.ns [l] # rewritecond %{http_user_agent} ^lynx/.* [or] # rewritecond %{http_user_agent} ^mozilla/[12].* # rewriterule ^foo\ $ foo.20 [l] # rewriterule ^foo\ $ foo.32 [l] # 阻止robots # 说明: # 如何阻止一个完全匿名的robot取得特定网络区域的页面? # 一个/robots.txt文件可以包含若干"robot exclusion protocol(robot排除协议)"的行, # 但不足以阻止此类robot。 # 方案: # 可以用一个规则集以拒绝对网络区域/~quux/foo/arc/ # (对一个很深的目录区域进行列表可能会使服务器产生很大的负载)的访问。 # 还必须确保仅阻止特定的robot,就是说,仅仅阻止robot访问主机是不够的, # 这样会同时也阻止了用户访问该主机。为此,就需要对http头的user-agent信息作匹配。 # rewritecond %{http_user_agent} ^nameofbadrobot.* # rewritecond %{remote_addr} ^123\.45\.67\.[8-9]$ # rewriterule ^/~quux/foo/arc/.+ - [f] # 防止盗链图片 # 说明: # 假设,http://gi.2288.org:88/myalbum/有一些内嵌图片的页面, # 这些图片很好,所以就有人用超链连到他们自己的页面中了。 # 由于这样徒然增加了我们的服务器的流量,因此,我们不愿意这种事情发生。 # 方案: # 虽然,我们不能100%地保护这些图片不被写入别人的页面, # 但至少可以对发出http referer头的浏览器加以限制。 # rewritecond %{http_referer} !^$ # rewritecond %{http_referer} !^http://gi.2288.org:88/myalbum/.*$ [nc] # rewriterule .*\.gif$ - [f] # rewritecond %{http_referer} !^$ # rewritecond %{http_referer} !.*/foo-with-gif\.html$ # rewriterule ^inlined-in-foo\.gif$ - [f] ########其他 # 禁止盗链 # setenvifnocase referer "^http://gi.2288.org:88/" local_ref=1 # # order allow,deny # allow from env=local_ref # # 加载 php 5 # loadmodule php5_module c:\php\php5apache2.dll # #addmodule mod_php4.c # addtype application/x-httpd-php .php # scriptalias /php/ "c:/php/" # addtype application/x-httpd-php .php # action application/x-httpd-php "/php/php-cgi.exe" # 本人如发现问题或错误将会随时修正,如有引用请注明原地址. - by emerald 2005-2-15 # /****************************************************************# * # * author : emerald # * # * homepage : http://gi.2288.org:88/ # * # * seo-gi : http://seo.2288.org:99 # * # * sitename : 绿色学院 - green institute # * # * date : 2005-2-15 2:03:35 # * # \****************************************************************/


html 文件: *.html

本文关键:apache note | Apache 学习笔记(心得) by Emerald 绿色学院 - Green Institute
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top