apache note Apache 学习笔记(心得)
# 说明: 设定针对cookies的日志文件名
# 模块: mod_log_config
# RewriteLog
# 语法: RewriteLog file-path
# 说明: 设置重写引擎日志的文件名
# 模块: mod_rewrite
# 例: RewriteLog "/usr/local/var/apache/logs/rewrite.log" (Unix/Linux)
# RewriteLog "G:/Apache/rewrite.log" (Windows)
# 一些常见的格式串如下所示:
# 能用日志格式(CLF): "%h %l %u %t \"%r\" %>s %b"
# 带虚拟主机的通用日志格式: "%v %h %l %u %t \"%r\" %>s %b"
# NCSA扩展/组合日志格式: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
# Referer日志格式: "%{Referer}i -> %U"
# Agent (Browser)日志格式: "%{User-agent}i"
########6.URL Rewrite
# 注意:根据你的服务器配置,可能有必要对例子作些微修改,
# 比如,新启用 mod_alias 和 mod_userdir 时要增加[PT]标志,
# 或者重写 .htaccess 而不是单个服务器中的规则集。
# 对一个特定的规则集应该首先去理解而后再去用以避免出问题。
# 重写语法
# 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
# <FilesMatch ".(gif|jpg|png|jpeg|zip|rar|exe|swf|txt)">
# Order Allow,Deny
# Allow from env=local_ref
# </FilesMatch>
# 加载 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<btbtd@yahoo.com.cn>
# *
# * homepage : http://gi.2288.org:88/
# *
# * Seo-Gi : http://seo.2288.org:99
# *
# * sitename : 绿色学院 - Green Institute
# *
# * date : 2005-2-15 2:03:35
# *
# \****************************************************************/
Tags:apache,note,Apache,学习,笔记,心得

