Board logo

¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!! [¥´¦L¥»­¶]

§@ªÌ: FIEND    ®É¶¡: 2003-2-28 21:21     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!

Apache Rewrite Module
The mod_rewrite Apache module is one of the best tools you can have on your server to help prevent unauthorized sites "hotlinking" your images or other files. Providing that your server has been set up for it, you can use this module for a number of things.

To prevent unauthorised use of files and images
To hide the real location of files on the server
To translate script input from one format to another
To redirect the user based on...
time of day
file they accessed
network they are connecting from
or anything else that can identify them as part of a "group" of users
Preventing Hotlinking
The most common use of the RewriteEngine is to limit access to specific file types on the server. To do this, you will need to add some rules and conditions to your .htaccess file so that the server knows what to look for and what to do when it finds requests that don't meet the criteria.

When editing your .htaccess file it is recommended that you use Notepad or equivalant to keep the file clean. Remember to upload the file in ASCII mode!

Here is a generic version of the code you will want to use. Of course you will need to make changes before it will work the way you want it to; replace all instances of you.com with your own domain name and add or remove file types as you see fit.

Rewriteengine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.your_domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.trusted.com/.*$ [NC]
RewriteRule .*.(gif|GIF|jpg|JPG)$ - [F]

How does it Work?
It's all very well having the code, but you may be interested to know how it works so that you can have a go at editing it to behave more like you want it to. If you ever want to disable the rules, it is much better to use the Rewriteengine statement to switch them off as opposed to commenting them out or deleting them from your file.

The RewriteCond lines tells the server to look for requests with HTTP_REFERER strings that are not empty and that match valid uses of your domain as you define them in the file.

The ! at the start of the condition pattern means not, and so negates the result of the pattern that follows it. ^ and $ are special characters used to match the start and the end of the string in question. So the pattern ^http:// would look for strings starting in http:// and gif$ would match strings ending in gif. The sequence .* will match any character for 0 or more times, and so adding it to the start or end of a particular string will allow fuzzy pattern matching of sorts.

The [NC] flag at the end of the RewriteCond lines tells the server to ignore the case (no case) while looking for matches.

The RewriteRule line tells the server how to deal with the requests that match the condition. In this case it is looking for requests to image files that end in .gif or .jpg (either in all capital letters or all lower case, the options to match are shown in brackets separated by the | character). Note that the . has to be un-escaped by adding a  in front of it as it is the special character that denotes other characters.

When it finds a request that has passed all the conditions and matches the rule, it will rewrite the request with -, although this could just as easily go to a page on your site. Finally the [F] flag tells the server how to respond to the request, in this particular case, it will tell the browser that it is forbidden from retrieving that file.

                    
§@ªÌ: FIEND    ®É¶¡: 2003-2-28 23:29     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!


Apache HTTP Server Version 1.3
Apache 1.3
URL­«¾É«ü«n

­ìµÛ¡G
Ralf S. Engelschall <rse@apache.org>
1997¦~12¤ë
¥»³¹¬Omod_rewrite°Ñ¦Ò»¡©ú¤å¥óªº¸É¥R¤Î¨Ï¥Î«ü¾É¡Aºô¯¸¤H­û¥i°Ñ¦Ò³o¤@³¹¦p¦ó«ü¾É§A§Q¥ÎApache mod_rewrite¨Ó¸Ñ¨MURLªº±`¨£°ÝÃD¡A¨C¤@ºØ¥Îªk³£¦³¨Ò¤l¸òÀH¡C

mod_rewrite¤Jªù
Apache mod_rewrite¼Ò²Õ¬O¤@­Ó³B²zURL¦Ó¤S·¥¬°½ÆÂøªº¼Ò²Õ¡A¨Ï¥Îmod_rewrite§A¥i³B²z©Ò¦³©MURL¦³Ãöªº°ÝÃD¡A§A©Ò¥I¥Xªº´N¬Oªá®É¶¡¥h¤F¸Ñmod_rewriteªº½ÆÂø¬[ºc¡A¤@¯ëªì¾ÇªÌ³£«ÜÃø§Y®É²z¸Ñmod_rewriteªº¥Îªk¡A¦³®ÉApache±M®a¤]­nmod_rewrite¨Óµo®iApacheªº·s¥¯à¡C
´«¥y¸Ü»¡¡A·í§A¦¨¥¨Ï¥Îmod_rewrite°µ¨ì§A´Á±æªºªF¦è¡A´N¤£­n¸Õ¹Ï¦A±µÄ²mod_rewrite¤F¡A¦]¬°mod_rewriteªº¥¯à¹ê¦b¹L©ó±j¤j¡C¥»³¹ªº¨Ò¤l·|¤¶²Ð´X­Ó¦¨¥ªº¨Ò¤lµ¹§AºN¯Á¡A¤£¹³FAQ§Î¦¡¯ë§â§Aªº°ÝÃD¸Ñµª¡C

¹ê¥Î¸Ñ¨M¤èªk
³o¸ÌÁÙ¦³«Ü¦h¥¼³Qµo±¸ªº¸Ñ¨M¤èªk¡A½Ð¤j®a­@¤ß¦a¾Ç²ß¦p¦ó¨Ï¥Îmod_rewrite¡C ª`·N: ¥Ñ©ó¦U¤Hªº¦øªA¾¹ªº°t¸m³£¦³©Ò¤£¦P¡A§A¥i¯à­n§ó§ï³]©w¨Ó´ú¸Õ¥H¤U¨Ò¤l¡A¨Ò¦p¨Ï¥Îmod_alias©Mmod_userdir®É­n¥[¤W[PT]¡A©ÎªÌ¨Ï¥Î.htaccess¨Ó­«¾É¦Ó«D¥D³]©w¤å¥óµ¥¡A½ÐºÉ¶q²z¸Ñ¦U¨Ò¤l¦p¦ó¹B§@¡A¤£­n¥Í§]¬¡­é¦a­I»w¡C

URL³W¹º
¥¿³WURL
´y­z:
¦b¬Y¨Çºô­¶¦øªA¾¹¤¤¡A¤@¶µ¸ê·½¥i¯à·|¦³¼Æ­ÓURL¡A³q±`³£·|¤½§G¤@¥¿³WURL(§Y¯u¥¿µo©ñªºURL)¡A¨ä¥LURL³£·|³Qµø¬°±¶®|©Î¥u¨Ñ¤º³¡¨Ï¥Îµ¥¡AµL½×¥Î¤á¦b¨Ï¥Î±¶®|©Î¥¿³WURL¡A¥Î¤á³Ì«á©Ò­«¾É¨ìªºURL¥²»Ý¬°¥¿³W¡C
¤èªk:
§Ú­Ì¥i±N©Ò¦³«D¥¿³WªºURL­«¾É¦Ü¥¿³WªºURL¤¤¡A¥H¤U¨Ò¤l§â«D¥¿³Wªº¡u/~user¡v´«¦¨¥¿³Wªº¡u/u/user¡v¡A¨Ã¥B¥[¤W¡u/¡v¸¹µ²§À¡C. RewriteRule   ^/~([^/]+)/?(.*)    /u/$1/$2  [R]
RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/   [R]


¥¿³W¥D¾÷¦WºÙ
´y­z:
(¬Ù²¤)
¤èªk:
RewriteCond %{HTTP_HOST}   !^fully.qualified.domain.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST}   !^fully.qualified.domain.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R]


DocumentRoot³Q²¾°Ê
´y­z:
URLªº¡u/¡v³q±`³£·|¬M®g¨ìDocumentRoot¤W¡A¦ýDocumentRoot¦³®É¨Ã«D­«©l´N­­©w¦b¬Y­Ó¥Ø¿ý¤W¡A¥¦¥i¯à¥u¬O¤@­Ó©Î¦h­Ó¥Ø¿ýªº¹ï·Ó¦Ó¨o¡C¨Ò¦p§Ú­Ìªº¤ºÁpºô§}¬°/e/www/ (WWWªº¥D¥Ø¿ý)©M/e/sww/ (¤ºÁpºôªº¥D¥Ø¿ý)µ¥µ¥¡A¦]¬°©Ò¦³ªººô­¶¸ê®Æ³£©ñ¦b/e/www/¥Ø¿ý¤º¡A§Ú­Ì­n½T©w©Ò¦³¤º´Oªº¹Ï¹³³£¯à¥¿½TÅã¥Ü¡C
¤èªk:
§Ú­Ì¥u­n§â¡u/¡v­«¾É¦Ü¡u/e/www/¡v¡A¥Îmod_rewrite¨Ó¸Ñ¨M¤ñ¥Îmod_alias¨Ó¸Ñ¨M§ó¬°Â²¼ä¡A¦]¬°URL§O¦W¥u·|¤ñ¸ûURLªº«e³¡¤À¡A¦ý­«¾É¦]¥i¯à¯A¤Î¥t¤@¥x¦øªA¾¹¦Ó»Ý­n¤£¦Pªº«eºó³¡¤À(«eºó³¡¤À¤w¨üDocumentRoot­­¨î)¡A©Ò¥Hmod_rewrite¬O³Ì¦nªº¸Ñ¨M¤èªk:: RewriteEngine on
RewriteRule   ^/$  /e/www/  [R]


µ²§À±×½u°ÝÃD
´y­z:
¨C­Óºô¥D³£´¿¨ü¨ìµ²§À±×½u°ÝÃDªº§é¿i¡A­Y¦bURL¤¤¨S¦³µ²§À±×½u¡A¦øªA¾¹´N·|»{¬°URLµL®Ä¨Ãªð¦^¿ù»~¡A¦]¬°¦øªA¾¹·|®Ú¾Ú/~quux/foo¥h´M§äfoo³o­ÓÀɮסA¦Ó«DÅã¥Ü³o­Ó¥Ø¿ý¡C¨ä¹ê«Ü¦h®É­Ô¡A³o°ÝÃDÀ³¯d«Ý¥Î¤á¦Û¤v¥[¡u/¡v¥h¸Ñ¨M¡A¦ý¦³®É§A¤]¥i¥H§¹¦¨¨BÆJ¡C¨Ò¦p§A°µ¤F¦h¦¸URL­«¾É¡A¦Ó¥Øªº¦a¬°¤@­ÓCGIµ{¦¡¡C
¤èªk:
³Ìª½Æ[ªº¤èªk´N¬O¥OApache¦Û°Ê¥[¤W¡u/¡v¡A¨Ï¥Î¥~³¡­«¾É¥OÂsÄý¾¹¯à¥¿½T§ä¨ìÀɮסA­Y§Ú­Ì¥u°µ¤º³¡­«¾É¡A´N¥u¯à¥¿½TÅã¥Ü¥Ø¿ý­¶¡A¦b³o¥Ø¿ý­¶ªº¹Ï¹³ÀÉ·|¦]¬Û¹ïURLªº°ÝÃD¦Ó§ä¤£¨ì¡C¨Ò¦p§Ú­Ì½Ð¨D/~quux/foo/index.htmlªºimage.gif®É¡A­«¾É«á·|Åܦ¨/~quux/image.gif¡C
©Ò¥H§Ú­ÌÀ³¨Ï¥Î¥H¤U¤èªk:

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo$  foo/  [R]


³o¤èªk¤]¾A¥Î©ó.htaccessÀɦb¦U¥Ø¿ý¤º³]©w¡A¦ý³o³]©w·|Âл­ì¥ý¥D°t¸mÀÉ¡C

RewriteEngine  on
RewriteBase    /~quux/
RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           $1/  [R]


§Q¥Î§¡¤@ªºURLª©­±³W¹ººôµ¸¸s²Õ
´y­z:
©Ò¦³ªººô­¶¦øªA¾¹³£¦³¬Û¦PªºURLª©­±¡A§YµL½×¥Î¤á¦V­þ­Ó¥D¾÷µo¥X½Ð¨DURL¡A¥Î¤á³£·|±µ¦¬¨ì¬Û¦Pªººô­¶¡A¨ÏURL¿W¥ß©ó¦øªA¾¹¥»¨­¡C§Ú­Ìªº¥Øªº¦b©ó¦p¦ó¦bApache¦øªA¾¹¤£¯à¦^À³®É¡A³£¯à¦³¤@­Ó±`³W(¦Ó¤S¿W¥ß©ó¦øªA¾¹¹B§@)ªººô­¶¶Ç°eµ¹¥Î¤á¡A³]¥ßºôµ¸¸s²Õ¥i±N³oºô­¶°e¦Ü»·ºÝ¡C
¤èªk:
­º¥ý¡A¦øªA¾¹»Ý­n¤@¥~³¡¤å¥ó§âºô¯¸ªº¥Î¤á¡B¥Î¤á²Õ¤Î¨ä¥L¸ê®Æ¦sÀx¡A³o¤å¥óªº®æ¦¡¦p¤U
user1  server_of_user1
user2  server_of_user2
:      :
§â¥H¤W¸ê®Æ¦s¤Jmap.xxx-to-host¡CµM«á«ü¥Ü¦øªA¾¹§âURL­«¾É¡A¥Ñ

/u/user/anypath
/g/group/anypath
/e/entity/anypath
¦Ü

http://physical-host/u/user/anypath
http://physical-host/g/group/anypath
http://physical-host/e/entity/anypath
·í¦øªA¾¹±µ¦¬¨ì¤£¥¿½TªºURL®É¡A¦øªA¾¹·|¸òÀH¥H¤U«ü¥Ü§âURL¬M®g¨ì¯S©wªºÀÉ®×(­YURL¨Ã¨S¦³¬Û¹ïÀ³ªº°O¿ý¡A´N·|­«¾É¦Ü server0 ¤W):

RewriteEngine on

RewriteMap      user-to-host   txt:/path/to/map.user-to-host
RewriteMap     group-to-host   txt:/path/to/map.group-to-host
RewriteMap    entity-to-host   txt:/path/to/map.entity-to-host

RewriteRule   ^/u/([^/]+)/?(.*)   http://${user-to-host:$1|server0}/u/$1/$2
RewriteRule   ^/g/([^/]+)/?(.*)  http://${group-to-host:$1|server0}/g/$1/$2
RewriteRule   ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2

RewriteRule   ^/([uge])/([^/]+)/?$          /$1/$2/.www/
RewriteRule   ^/([uge])/([^/]+)/([^.]+.+)   /$1/$2/.www/$3


§â¥D¥Ø¿ý²¾¨ì·sªººô­¶¦øªA¾¹
´y­z:
¦³«Ü¦hºô¥D³£¦³¥H¤U°ÝÃD:¦b¤É¯Å®É§â©Ò¦³¥Î¤á¥D¥Ø¿ý¥Ñªº¦øªA¾¹²¾¨ì·sªº¦øªA¾¹¤W¡C
¤èªk:
¨Ï¥Îmod_rewrite¥i¥H²³æ¦a¸Ñ¨M³o°ÝÃD¡A§â©Ò¦³/~user/anypathURL­«¾É¦Ühttp://newserver/~user/anypath¡C RewriteEngine on
RewriteRule   ^/~(.+)  http://newserver/~$1  [R,L]


µ²ºc¤Æ¥Î¤á¥D¥Ø¿ý
´y­z:
¾Ö¦³¤j¶q¥Î¤áªº¥D¾÷³q±`³£·|§â¥Î¤á¥Ø¿ý³W¹º¦n¡A±N³o¨Ç¥Ø¿ýÂk¤J¤@­Ó¤÷¥Ø¿ý¤¤¡AµM«á¦A±N¥Î¤áªº²Ä¤@­Ó¦r¥À§@¸Ó¥Î¤áªº¤÷¥Ø¿ý¡A¨Ò¦p/~foo/anypath±N·|¬O/home/f/foo/.www/anypath¡A¦Ó/~bar/anypath´N¬O/home/b/bar/.www/anypath¡C
¤èªk:
«ö¥H¤U«ü¥O±NURLª½±µ¹ï¬M¨ìÀɮרt²Î¤¤¡C RewriteEngine on
RewriteRule   ^/~(([a-z])[a-z0-9]+)(.*)  /home/$2/$1/.www$3


­«·s²Õ´Àɮרt²Î
´y­z:
³o¬O¤@­Ó³Â·Ðªº¨Ò¤l:¦b¤£¥Î§ó°Ê²{¦³¥Ø¿ýµ²ºc¤U¡A¨Ï¥ÎRewriteRules¨ÓÅã¥Ü¾ã­Ó¥Ø¿ýµ²ºc¡C­I´º¡Gnet.sw¬O¤@­Ó¸Ëº¡Unix§K¶O³n¥óªº¸ê®Æ§¨¡A¨Ã¥H¤U¦Cµ²ºc¦sÀx¡G
drwxrwxr-x   2 netsw  users    512 Aug  3 18:39 Audio/
drwxrwxr-x   2 netsw  users    512 Jul  9 14:37 Benchmark/
drwxrwxr-x  12 netsw  users    512 Jul  9 00:34 Crypto/
drwxrwxr-x   5 netsw  users    512 Jul  9 00:41 Database/
drwxrwxr-x   4 netsw  users    512 Jul 30 19:25 Dicts/
drwxrwxr-x  10 netsw  users    512 Jul  9 01:54 Graphic/
drwxrwxr-x   5 netsw  users    512 Jul  9 01:58 Hackers/
drwxrwxr-x   8 netsw  users    512 Jul  9 03:19 InfoSys/
drwxrwxr-x   3 netsw  users    512 Jul  9 03:21 Math/
drwxrwxr-x   3 netsw  users    512 Jul  9 03:24 Misc/
drwxrwxr-x   9 netsw  users    512 Aug  1 16:33 Network/
drwxrwxr-x   2 netsw  users    512 Jul  9 05:53 Office/
drwxrwxr-x   7 netsw  users    512 Jul  9 09:24 SoftEng/
drwxrwxr-x   7 netsw  users    512 Jul  9 12:17 System/
drwxrwxr-x  12 netsw  users    512 Aug  3 20:15 Typesetting/
drwxrwxr-x  10 netsw  users    512 Jul  9 14:08 X11/
§Ú­Ì¥´ºâ§â³o­Ó¸ê®Æ§¨¤½¶}¡A¦Ó¥B§Æ±æª½±µ¦aÅã¥Ü³o¸ê®Æ§¨ªº¥Ø¿ýµ²ºc¡A¦ý¬O§Ú­Ì¤S¤£·Q§ó§ï²{¦³¥Ø¿ý¬[ºc¨Ó¾E´N¡A¥[¤W§Ú­Ì¥´ºâ¶}©ñµ¹FTP¡A©Ò¥H¤£·Q¥[¤J¥ô¦óºô­¶©ÎCGIµ{¦¡¨ì³o­Ó¸ê®Æ§¨¤¤¡C

¤èªk:
¥»¤èªk¤À¬°¨â³¡¤À¡G²Ä¤@³¡¥÷¬O½s¼g¤@¨t¦CªºCGIµ{¦¡¨ÓÅã¥Ü¥Ø¿ýµ²ºc¡A³o¨Ò¤l·|§âCGI©M­è¤~ªº¸ê®Æ§¨©ñ¶i/e/netsw/.www/¡G
-rw-r--r--   1 netsw  users    1318 Aug  1 18:10 .wwwacl
drwxr-xr-x  18 netsw  users     512 Aug  5 15:51 DATA/
-rw-rw-rw-   1 netsw  users  372982 Aug  5 16:35 LOGFILE
-rw-r--r--   1 netsw  users     659 Aug  4 09:27 TODO
-rw-r--r--   1 netsw  users    5697 Aug  1 18:01 netsw-about.html
-rwxr-xr-x   1 netsw  users     579 Aug  2 10:33 netsw-access.pl
-rwxr-xr-x   1 netsw  users    1532 Aug  1 17:35 netsw-changes.cgi
-rwxr-xr-x   1 netsw  users    2866 Aug  5 14:49 netsw-home.cgi
drwxr-xr-x   2 netsw  users     512 Jul  8 23:47 netsw-img/
-rwxr-xr-x   1 netsw  users   24050 Aug  5 15:49 netsw-lsdir.cgi
-rwxr-xr-x   1 netsw  users    1589 Aug  3 18:43 netsw-search.cgi
-rwxr-xr-x   1 netsw  users    1885 Aug  1 17:41 netsw-tree.cgi
-rw-r--r--   1 netsw  users     234 Jul 30 16:35 netsw-unlimit.lst
DATA/¤l¥Ø¿ý´N¬O­è¤~ªº¸ê®Æ§¨¡Anet.sw¤ºªº³n¥ó·|¸grdistµ{¦¡¨Ó¦Û°Ê§ó·s¡C²Ä¤G³¡¥÷±N³o¸ê®Æ§¨©M·s«Ø¥ßªºCGI¡Bºô­¶°t¦X¡A§Ú­Ì·Q±NDATA/íÂð_¨Ó¡A¦Ó¦b¥Î¤á½Ð¨D¤£¦PURL®É°õ¦æ¥¿½TªºCGIµ{¦¡¨ÓÅã¥Ü¡C¥ý±N/net.sw/³oURL­«¾É¦Ü/e/netsw¡G

RewriteRule  ^net.sw$       net.sw/        [R]
RewriteRule  ^net.sw/(.*)$  e/netsw/$1


²Ä¤@±ø³W«h¯Âºé¸É¥[URLµ²§Àªº¡u/¡v¸¹¡A¦Ó²Ä¤G±ø³W«h´N¬O§âURL­«¾É¡C¤§«á±N¤U¦C°t¸m¦s¤J/e/netsw/.www/.wwwacl¡G

Options       ExecCGI FollowSymLinks Includes MultiViews

RewriteEngine on

#  we are reached via /net.sw/ prefix
RewriteBase   /net.sw/

#  first we rewrite the root dir to
#  the handling cgi script
RewriteRule   ^$                       netsw-home.cgi     [L]
RewriteRule   ^index.html$            netsw-home.cgi     [L]

#  strip out the subdirs when
#  the browser requests us from perdir pages
RewriteRule   ^.+/(netsw-[^/]+/.+)$    $1                 [L]

#  and now break the rewriting for local files
RewriteRule   ^netsw-home.cgi.*       -                  [L]
RewriteRule   ^netsw-changes.cgi.*    -                  [L]
RewriteRule   ^netsw-search.cgi.*     -                  [L]
RewriteRule   ^netsw-tree.cgi$        -                  [L]
RewriteRule   ^netsw-about.html$      -                  [L]
RewriteRule   ^netsw-img/.*$           -                  [L]

#  anything else is a subdir which gets handled
#  by another cgi script
RewriteRule   !^netsw-lsdir.cgi.*     -                  [C]
RewriteRule   (.*)                     netsw-lsdir.cgi/$1


´£¥Ü:

¯d·N²Ä¥|³¡¥÷ªºL(last)ºX¼Ð¤Î¥Nªí¤£¥Î§ó§ïªº('-')²Å¸¹
¯d·N³Ì«á³¡¥÷²Ä¤@±ø³W«hªº ! (not)¦r¤¸¡A¤Î C (chain) Ãìµ²²Å
¯d·N³Ì«á¤@±ø³W«h¥Nªí¥þ³¡§ó·sªº»yªk
¥HApacheªºmod_imap¨ú¥NNCSAªºimagemap
´y­z:
«Ü¦h¤H³£·Q¶¶§Q¦a§âªºNCSA¦øªA¾¹¾E¦Ü·sªºApache¦øªA¾¹¡A©Ò¥H§Ú­Ì³£·Q±NªºNCSA imagemap¶¶§QÂà´«¨ìApacheªºmod_imap¡A°ÝÃD¬Oimagemap¤w³Q«Ü¦h¶W³sµ²³sôµÛ¡A¦ýªºimagemap¬O¦sÀx¦b/cgi-bin/imagemap/path/to/page.map¡A¦Ó¦bApache«o¬O©ñ¦b/path/to/page.map¡C
¤èªk:
§Ú­Ì¥u­n±N¡u/cgi-bin/¡v²¾°£«K¥i¡G RewriteEngine  on
RewriteRule    ^/cgi-bin/imagemap(.*)  $1  [PT]


¦b¦h­Ó¥Ø¿ý¤U·j´Mºô­¶
´y­z:
MultiViews¥ç¤£¯à«ü¥ÜApache¦b¦h­Ó¥Ø¿ý¸Ì·j´Mºô­¶¡C
¤èªk:
½Ð°Ñ¬Ý¥H¤U«ü¥O¡C RewriteEngine on

#   first try to find it in custom/...
#   ...and if found stop and be happy:
RewriteCond         /your/docroot/dir1/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir1/$1  [L]

#   second try to find it in pub/...
#   ...and if found stop and be happy:
RewriteCond         /your/docroot/dir2/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir2/$1  [L]

#   else go on for other Alias or ScriptAlias directives,
#   etc.
RewriteRule   ^(.+)  -  [PT]


¸ò¾ÚURL³]©wÀô¹ÒÅܼÆ
´y­z:
¦b­¶­±¶¡¶Ç»¼°T®§¥i¥H¥ÎCGIµ{¦¡§¹¦¨¡A¦ý§A«o¤£·Q¥ÎCGI¦Ó¥ÎURL¨Ó¶Ç»¼¡C
¤èªk:
¥H¤U«ü¥O±NÅܼƤΨä­È©â¥XURL¥~¡AµM«á°O¤J¦Û³]ªºÀô¹ÒÅܼƤ¤¡A¸ÓÅܼƥi¥ÑXSSI©ÎCGI¦s¨ú¡C¨Ò¦p§â/foo/S=java/bar/Âà´«¬°/foo/bar/¡AµM«á§â¡ujava¡v¼g¤JÀô¹ÒÅܼơuSTATUS¡v¡C RewriteEngine on
RewriteRule   ^(.*)/S=([^/]+)/(.*)    $1/$3 [E=STATUS:$2]


µêÀÀ¥Î¤á¥D¾÷
´y­z:
§A¥u·Q®Ú¾ÚDNS°O¿ý±Nwww.username.host.domain.comªº½Ð¨Dª½±µ¹ï¬M¨ìÀɮרt²Î¡A©ñ±ó¨Ï¥ÎApacheªºµêÀÀ¥D¾÷¥¯à¡C
¤èªk:
¥u¦³HTTP/1.1½Ð¨D¤~¥i¥Î¥H¤U¤èªk°µ¨ì¡A§Ú­Ì¥i®Ú¾ÚHTTP Header§âhttp://www.username.host.com/anypath­«¾É¨ì/home/username/anypath¡G RewriteEngine on
RewriteCond   %{HTTP_HOST}                 ^www.[^.]+.host.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^www.([^.]+).host.com(.*) /home/$1$2


±N»·ºÝ½Ð¨D­«¾É¦Ü¥t¤@­Ó¥Î¤á¥D¥Ø¿ý
´y­z:
·í¥ÎªÌªº¥D¾÷¤£ÄÝ©ó¦Û¤vªººô°ìourdomain.com®É¡A´N±N½Ð¨D­«¾É¦Üwww.somewhere.com
¤èªk:
½Ð°Ñ¬Ý¥H¤U«ü¥O: RewriteEngine on
RewriteCond   %{REMOTE_HOST}  !^.+.ourdomain.com$
RewriteRule   ^(/~.+)         http://www.somewhere.com/$1 [R,L]


±N¥¢±Ñªººô­¶½Ð¨D­«¾É¦Ü¥t¤@³¡ºô­¶¦øªA¾¹
´y­z:
³o¬O¤@¯ë±`¨£ªººÃ°Ý¡A³Ìª½Æ[ªº¤èªk´N¬O¥ÎErrorDocument¥[¤WCGI-scripts§ó§ï¥Ø¼ÐURL¡A¦ý§Ú­Ì¥ç¥i¨Ï¥Îmod_rewrite¨Ó¹ê¦æ(³o¤èªkªº®Ä²v«o¤ñCGIµ{¦¡§ó§C)¡C
¤èªk:
¦A¤@¦¸¯d·NCGI·|¬O§ó¦³®Ä²vªº¸Ñ¨M¤èªk¡A¦Ómod_rewriteªº¦n³B¦b©ó§ó¦w¥þ¤Î©ö³]¸m: RewriteEngine on
RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule   ^(.+)                             http://webserverB.dom/$1


¥H¤W¨Ò¤l·|­­¨î©Ò¦³ºô­¶¦bDocumentRoot¤~¯à¦¨¥¡A§Ú­Ì¥i¥[¦h¤@ÂI«ü¥O¨Ó§ïµ½¡G

RewriteEngine on
RewriteCond   %{REQUEST_URI} !-U
RewriteRule   ^(.+)          http://webserverB.dom/$1


³o¨Ò¤l¨Ï¥Î¤Fmod_rewrite¹w­pURL§ï°Êªº¥¯à¡A©Ò¦³URL³£¥i¥H¦w¥þ¦a­«¾É¦Ü·sªº¥Ø¿ý¡A¦ý¦b³t«×ºCªº¥D¾÷¤W¤£©y¨Ï¥Î³o¤èªk¡A¦]¬°±Ä¥Î¥»¨Ò·|©ìºC¦øªA¾¹¤u§@¡A·íµM§A¥i¥H¦b°ª³tCPU¥D¾÷¤W¨Ï¥Î¡C

§ó¼sªxªºURL­«¾É
´y­z:
§Ú­Ì·Q­«¾É¦³±±¨î¦r¤¸ªºURL¡A¨Ò¦p&quot;url#anchor&quot;µ¥¡A³q±`Apache·|¥Îuri_escape()¨ç¼Æ¨Ó¹j°£³o¨Ç±±¨î¦r¤¸¡A¦]¦¹§A¤£¥i¥Hª½±µ¥Îmod_rewrite¨Ó­«¾É³oÃþURL¡C
¤èªk:
§Ú­Ì­n¨Ï¥Î¤@NPH-CGI(NPH = non-parseable headers)µ{¦¡³B²z­«¾É¤u§@¡A¦]¬°NPH-CGI¤£·|¹j°£±±¨î¦r¤¸¡C­º¥ý¡A§Ú­Ì¥ý§Q¥Îxredirect¡G RewriteRule ^xredirect.+) /path/to/nph-xredirect.cgi/$1
            [T=application/x-httpd-cgi,L]


±j¨î©Ê±N©Ò¦³URL¥[¤Wxredirect¡AµM«á±NURL¾É¤Jnph-xredirect.cgi¤¤¡Aµ{¦¡½X¦p¤U¡G

#!/path/to/perl
##
##  nph-xredirect.cgi -- NPH/CGI script for extended redirects
##  Copyright &copy; 1997 Ralf S. Engelschall, All Rights Reserved.
##

$| = 1;
$url = $ENV{'PATH_INFO'};

print &quot;HTTP/1.0 302 Moved Temporarilyn&quot;;
print &quot;Server: $ENV{'SERVER_SOFTWARE'}n&quot;;
print &quot;Location: $urln&quot;;
print &quot;Content-type: text/htmln&quot;;
print &quot;n&quot;;
print &quot;<html>n&quot;;
print &quot;<head>n&quot;;
print &quot;<title>302 Moved Temporarily (EXTENDED)</title>n&quot;;
print &quot;</head>n&quot;;
print &quot;<body>n&quot;;
print &quot;<h1>Moved Temporarily (EXTENDED)</h1>n&quot;;
print &quot;The document has moved <a HREF=&quot;$url&quot;>here</a>.<p>n&quot;;
print &quot;</body>n&quot;;
print &quot;</html>n&quot;;

##EOF##


³o¼Ë¥i±N©Ò¦³¯à©Î¤£¯àª½±µ¥Îmod_rewrite¨Ó­«¾ÉªºURL¡A¸gCGI¨Ó§¹¦¨¤F¡C¨Ò¦p§A¥i±N¬YURL­«¾É¦Ü·s»D¦øªA¾¹

RewriteRule ^anyurl  xredirect:news:newsgroup


ª`·N¡G§A¤£»Ý¦b¨C±ø³W«h«á¥[¤W[R]©Î[R,L]¡C

¦h¼Ë¤Æ¸ê®Æ§¨¦s¨ú
´y­z:
­Y§A´¿ÂsÄýhttp://www.perl.com/CPAN (CPAN = Comprehensive Perl Archive Network)¡A¥¦·|§â§A­«¾É¦Ü¨ä¤¤¤@­Ó³Ìªñ§A¥D¾÷¦a°ÏªºFTP¦øªA¾¹¡A¨Æ¹ê¤W³oÀ³¸Ó¥s¦h¼Ë¤ÆFTP¦s¨ú¡CCPAN¥ÎCGI¨Ó¹ê¦æ³oªA°È¡A³o¦¸§Ú­Ì¥Îmod_rewrite¡C
¥Ñmod_rewrite 3.0.0¶}©l¥i¨Ï¥Î¡uftp:¡v­«¾É¦ÜFTP¦øªA¾¹¡A¥Î¤á¥D¾÷ªº¦a°Ï¥i¨ÌURLªº³»¼h°ì¦W¨Ó¨M©w¡A¦Ó³»¼h°ì¦W¤ÎFTP¦øªA¾¹¦ì¸mªº¹ï·Ó´N¦s¤J¬YÀɮפ¤¡C RewriteEngine on
RewriteMap    multiplex                txt:/path/to/map.cxan
RewriteRule   ^/CxAN/(.*)              %{REMOTE_HOST}::$1                 [C]
RewriteRule   ^.+.([a-zA-Z]+):.*)$  ${multiplex:$1|ftp.default.dom}$2  [R,L]

##
##  map.cxan -- Multiplexing Map for CxAN
##

de        ftp://ftp.cxan.de/CxAN/
uk        ftp://ftp.cxan.uk/CxAN/
com       ftp://ftp.cxan.com/CxAN/
:
##EOF##


¦b¬Y¬q®É¶¡°õ¦æ¤£¦Pªº­«¾É
´y­zn:
«Ü¦hºô¥D¤´¥ÎCGIÀHµÛ¤£¦P®É¶¡±NURL­«¾É¦Ü¤£¦Pªººô­¶¡C
¤èªk:
mod_rewrite³]¦³«Ü¦h¥HTIME_xxx¶}©lªºÀô¹ÒÅܼơA±N³o¨Ç®É¶¡Àô¹ÒÅܼƶi¦æ¦r¦ê¤ñ¸û¥i¨M©w­«¾É¦Ü­þ­Óºô­¶¡G RewriteEngine on
RewriteCond   %{TIME_HOUR}%{TIME_MIN} >0700
RewriteCond   %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule   ^foo.html$             foo.day.html
RewriteRule   ^foo.html$             foo.night.html


¦b07:00-19:00´NÅã¥Üfoo.day.html¡A¨ä¾l®É¶¡«hÅã¥Üfoo.html

«O¯d¦³¤å¥óªºURL
´y­z:
§ó§ï¤å¥óªº°ÆÀɦW«á¡A¦p¦óÅýªºURL¯à¹ï¬M¨ì³o·sªº¤å¥ó¡C
¤èªk:
§âªºURL¥Îmod_rewrite­«¾É¦Ü·sªº¤å¥ó¡A­Y¦³¥¿½Tªº·s¤å¥ó´N¹ï¬M¨ì³o¤å¥ó¡A¨S¦³ªº¸Ü«K¹ï¬M¨ì­ì¦³¤å¥ó¡C #   backward compatibility ruleset for
#   rewriting document.html to document.phtml
#   when and only when document.phtml exists
#   but no longer document.html
RewriteEngine on
RewriteBase   /~quux/
#   parse out basename, but remember the fact
RewriteRule   ^(.*).html$              $1      [C,E=WasHTML:yes]
#   rewrite to document.phtml if exists
RewriteCond   %{REQUEST_FILENAME}.phtml -f
RewriteRule   ^(.*)$ $1.phtml                   [S=1]
#   else reverse the previous basename cutout
RewriteCond   %{ENV:WasHTML}            ^yes$
RewriteRule   ^(.*)$ $1.html


¤º®e±±¨î
¥ÑªºÀɦWÂà¨ì·sªºÀɦW (Àɮרt²Î)
´y­z:
°²³]§Ú­Ì±Nbar.html§ï¦W¬°foo.html¡A¦Ó§Ú­Ì¤S·Q«O¯d¦³ªºURL¡A¬Æ¦Ü¤£·Qµ¹¥Î¤á·sªºURL¥h³s¦Ü³o·sÀɮסC
¤èªk:
±NªºÀÉ®×¹ï¬M¨ì·sªºÀɮסG RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo.html$  bar.html


¥ÑªºÀɦWÂà¨ì·sªºÀɦW (URL)
´y­z:
©M­è¤~ªº¨Ò¤l¤@¼Ë¡A§Ú­Ì§âbar.html§ï¦W¬°foo.html¡A¦ý³o¦¸§Ú­Ì·Qª½±µ±N¥Î¤áªººô­¶­«¾É¦Ü·sªº¤å¥ó¡A§YÂsÄý¾¹ªºURL¦ì¸m¦³©Ò§ïÅÜ¡C
¤èªk:
±j¨î©Ê±NURL¹ï¬M¨ì·sªºURL¡G RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo.html$  bar.html  [R]


¥ÑÂsÄý¾¹ºØÃþ±±¨î¤º®e
´y­z:
¤@­Ó¥X¦âªººô­¶À³¯à¤ä´©¦UºØÂsÄý¾¹¡A¨Ò¦p§Ú­Ì­n§â§¹¾ãª©ºô­¶¶Ç°e¦ÜNetscape¡A¦ý´N­n¶Ç°e¤å¦rª©¦ÜLynx¡C
¤èªk:
¥Ñ©óÂsÄý¾¹¨S¦³´£¨ÑApache®æ¦¡ªºÂsÄý¾¹ºØÃþ¸ê®Æ¡A©Ò¥H§Ú­Ì¤£¥i¨Ï¥Î¤º¤åÂà´«(mod_negotiation)¡A§Ú­Ì¥²»Ý¥Î¡uUser-Agent¡v¨M©wÂsÄý¾¹ºØÃþ¡C¨Ò¦pUser-Agent¬°¡uMozilla/3¡v´N§â¡ufoo.html¡v­«¾É¦Ü¡ufoo.NS.html¡v¡F­YÂsÄý¾¹¬°¡uLynx¡v©Î¡uMozilla¡v´N­«¾É¦Üfoo.20.html¡A¨ä¥LºØÃþªºÂsÄý¾¹«h¾É¦V¦Üfoo.32.html¡G RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/3.*
RewriteRule ^foo.html$         foo.NS.html          [L]

RewriteCond %{HTTP_USER_AGENT}  ^Lynx/.*         [OR]
RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/[12].*
RewriteRule ^foo.html$         foo.20.html          [L]

RewriteRule ^foo.html$         foo.32.html          [L]


°ÊºA¥»¦aÀÉ®×§ó·s(¸gÃè¹³ºô¯¸)
´y­z:
§A·Q±N¬Y­Ó¥D¾÷ªººô­¶³sµ²¨ì§Aªººô­¶¥Ø¿ý¡A­Y³Q³sµ²ªº¬OFTP¦øªA¾¹¡A§A¥i¥Îmirrorµ{¦¡±N³Ì·sªºÀɮײ¾¨ì¦Û¤vªº¥D¾÷¤W¡A§Ú­Ì¥i¥Îwebcopy¸gºô­¶¦øªA¾¹HTTP§âÀɮפU¸ü¡A¦ý³o¤èªk¦³¤@Ãa³B¡G¥u¦³¦b°õ¦æwebcopy®É¤~¯à§ó·sÀɮסC§ó¦nªº¿ìªk´N¬O¦bµo¥X½Ð¨D®É¥ß¨è§ä´M³Ì·sªºÀɮרӷ½¡AµM«á§Y®É¤U¸ü¨ì¦Û¤v¥D¾÷¤¤¡C
¤èªk:
§Q¥ÎProxy Throughput(flag [P])§â»·ºÝºô­¶¬Æ¦Ü¾ã­Óºô¯¸«Ø¥ß¤@ª½±µ¹ï·Ó¡C RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^hotsheet/(.*)$  http://www.tstimpreso.com/hotsheet/$1  [P]

RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^usa-news.html$   http://www.quux-corp.com/news/index.html  [P]


°ÊºAÃè¹³ÀÉ®×§ó·s(¸g¥»¥D¾÷)
´y­z:
(¬Ù²¤)
¤èªk:
RewriteEngine on
RewriteCond   /mirror/of/remotesite/$1           -U
RewriteRule   ^http://www.remotesite.com/(.*)$ /mirror/of/remotesite/$1


¥Ñ¤º³¡ºôµ¸§ó·sÀÉ®×
´y­z:
¬°¤F¦w¥þ°_¨£¡A§Ú­Ì«Ø¥ß¤F¨â­Óºô­¶¦øªA¾¹¡A²Ä¤@­Ó¬O¤½¶}ªº(www.quux-corp.dom)¡A²Ä¤G­Ó«h¬O¤º³¡¨Ï¥Î¡A¨ü¨¾¤õÀð©Ò«OÅ@¡A¤@¤Á¸ê®Æ¤Îºô¯¸ºûÅ@³£¸g³o­Ó¦øªA¾¹¶i¦æ¡A²{¦b§Ú­Ì·Q¥O¥~³¡¦øªA¾¹¯à¦s¨ú¬ï¹L¨¾¤õÀð¡AÀò¨ú¤º³¡¦øªA¾¹¤w³Ì·sªºÀɮסC
¤èªk:
§Ú­Ì¥u®e³¥~³¡¦øªA¾¹±q¤º³¡Àò¨ú¸ê®Æ¡A¤@¤Áª½±µÀò¨úªº½Ð¨D³£¨ü¨¾¤õÀð©Úµ´¡A¥ý¦b¨¾¤õÀð³]©w¡G ALLOW Host www.quux-corp.dom Port >1024 --> Host www2.quux-corp.dom Port 80  
DENY  Host *                 Port *     --> Host www2.quux-corp.dom Port 80


§â¥H¤Wªº¦r¥yͦ¨³]¸m¨¾¤õÀ𪺻yªk¡AµM«á¦bmod_rewrite³z¹Lproxy throughputÀò¨ú³Ì·s¸ê®Æ¡G

RewriteRule ^/~([^/]+)/?(.*)          /home/$1/.www/$2
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom/~$1/pub/$2 [P]


¥­¿Å¦øªA¾¹­t²ü
´y­z:
§Ú­Ì·Q±Nwww[0-5].foo.com³o¤»³¡¦øªA¾¹ªº¤u§@¶q¥­§¡¤À°t¡C
¤èªk:
·íµM§A·|¦³«Ü¦h¤èªk¹F¦¨¡A¤@¯ë³£·|¨Ï¥ÎDNS¡A¤¶²Ð§¹DNS«á¦A·|°Q½×mod_rewrite¦p¦ó¹ê¦æ¡C
DNS´`Àô¾÷¨î
³Ì²³æªº¤èªk´N¬O¨Ï¥ÎBINDªº´`Àô¾÷¨î¡Ae.g.

www0   IN  A       1.2.3.1
www1   IN  A       1.2.3.2
www2   IN  A       1.2.3.3
www3   IN  A       1.2.3.4
www4   IN  A       1.2.3.5
www5   IN  A       1.2.3.6


µM«á¥[¤W¥H¤U°O¿ý¡G

www    IN  CNAME   www0.foo.com.
       IN  CNAME   www1.foo.com.
       IN  CNAME   www2.foo.com.
       IN  CNAME   www3.foo.com.
       IN  CNAME   www4.foo.com.
       IN  CNAME   www5.foo.com.
       IN  CNAME   www6.foo.com.


¦bDNS¼h­±¤W³oºØ³]©w·íµM¬O¿ùªº¡A¦ý§Ú­Ì¥¿¦n¨Ï¥Î¤FBINDªº´`Àô¾÷¨î¡ABIND±µ¦¬¨ìwww.foo.comªº¸ÑªR½Ð¨D¡AµM«áBIND´N·|´`Àô¦a¸ÑªR§@www0-www6¡A³o¼Ë´N¯à±N¥Î¤á¤À°t¨ì¤£¦Pªº¦øªA¾¹¤W¡A¦ý½Ð°O±o³o¤£¬O¤@­Ó§¹¬üªº¤è®×¡A¦]¬°¨ä¥Lªº°ì¦W¦øªA¾¹·|§Ö¨ú§A¦øªA¾¹ªº°ì¦W¸ÑªRµ²ªG¡A©Ò¥H¨C¤@¦¸¸ÑªR¨ìwwwX.foo.com®É¡A³£·|¦³«Ü¦h¥Î¤á¦P®É³Q¬£©¹¦P¤@³¡¦øªA¾¹¡A¦ý¾ãÅé¨Ó»¡¤w¯à¥­¿Å¦U¦øªA¾¹ªº­t²ü¡C

DNS¥­¿Å­t²ü
¦bhttp://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html¦³¤@­Ólbnamedµ{¦¡±M³d§Q¥Î°ì¦W¦øªA¾¹§â¥Î¤á½Ð¨D¤Àµo¨ì¤£¦Pªº¦øªA¾¹¤W¡A³o¬O¤@­Ó¥ÎPerl 5¤Î¨ä¥Lªþ§U¤u¨ã¼gªº½ÆÂøDNS¤u§@¶q¤À°tµ{¦¡¡C

¥N²z¦øªA¾¹´`Àô«Ø¥ß¾÷¨î
§Ú­Ì¨Ï¥Îmod_rewrite¤Î¨ä¥N²z¦øªA¾¹ºô­¶°O¿ý(proxy throughput)¥¯à¡A¥ý¦bDNS¥[¤Jwww0.foo.com§Y¬Owww.foo.comªº°O¿ý¡C

www    IN  CNAME   www0.foo.com.


µM«á±Nwww0.foo.comÅܬ°¤@¿W¥ß¥N²z¦øªA¾¹¡A§Y¬O«Ø¥ß¤@±M³d¥N²z¦øªA¾¹¡AµM«á§â½Ð¨D¤À¬y¦Ü¤­³¡¤£¦Pªº¦øªA¾¹(www1-www5)¡A§Ú­Ì¥Îlb.pl¤Î¥H¤Umod_rewrite³W«h¡G

RewriteEngine on
RewriteMap    lb      prg:/path/to/lb.pl
RewriteRule   ^/(.+)$ ${lb:$1}           [P,L]


lb.plªºµ{¦¡½X¡G

#!/path/to/perl
##
##  lb.pl -- load balancing script
##

$| = 1;

$name   = &quot;www&quot;;     # the hostname base
$first  = 1;         # the first server (not 0 here, because 0 is myself)
$last   = 5;         # the last server in the round-robin
$domain = &quot;foo.dom&quot;; # the domainname

$cnt = 0;
while (<STDIN>) {
    $cnt = (($cnt+1) % ($last+1-$first));
    $server = sprintf(&quot;%s%d.%s&quot;, $name, $cnt+$first, $domain);
    print &quot;http://$server/$_&quot;;
}

##EOF##


ª`·N¡Awww0.foo.com³o¦øªA¾¹ªº¤u§@¶q¤´µM©M¥H«e¤@¼Ë°ª¡A¦ý³o¦øªA¾¹ªº¤u§@´N¥u¬O­t³d¤À¬y¡A©Ò¦³SSI¡BCGI¡BePerl½Ð¨D³£¥Ñ¨ä¥L¦øªA¾¹°õ¦æ¡A©Ò¥H¾ãÅ骺¤u§@¶q¤w¸g´î¤Ö¤F³¦h¡C

µw¥ó/TCP´`Àô¾÷¨î
¥iCiscoªºLocalDirector¦bTCP/IPºôµ¸¼h¤W§â¥Î¤á½Ð¨D¤À¬y¡A¨Æ¹ê¤W³oºØ¤À¬yµ{§Ç¤w¨è¯O¦b¬O¹q¸ôªO¤W¡C»Pµw¥ó¦³Ãöªº¸Ñ¨M¤èªk³q±`³£»Ý­n¤j¶qªºª÷¿ú¡A¦ý°õ¦æ®Ä²v´N·|¬O³Ì°ª¡C

±N½Ð¨D­«¾É¦Ü¥N²z¦øªA¾¹
´y­z:
(¬Ù²¤)
¤èªk:
##
##  apache-rproxy.conf -- Apache configuration for Reverse Proxy Usage
##

#   server type
ServerType           standalone
Port                 8000
MinSpareServers      16
StartServers         16
MaxSpareServers      16
MaxClients           16
MaxRequestsPerChild  100

#   server operation parameters
KeepAlive            on
MaxKeepAliveRequests 100
KeepAliveTimeout     15
Timeout              400
IdentityCheck        off
HostnameLookups      off

#   paths to runtime files
PidFile              /path/to/apache-rproxy.pid
LockFile             /path/to/apache-rproxy.lock
ErrorLog             /path/to/apache-rproxy.elog
CustomLog            /path/to/apache-rproxy.dlog &quot;%{%v/%T}t %h -> %{SERVER}e URL: %U&quot;

#   unused paths
ServerRoot           /tmp
DocumentRoot         /tmp
CacheRoot            /tmp
RewriteLog           /dev/null
TransferLog          /dev/null
TypesConfig          /dev/null
AccessConfig         /dev/null
ResourceConfig       /dev/null

#   speed up and secure processing
<Directory />
Options -FollowSymLinks -SymLinksIfOwnerMatch
AllowOverride None
</Directory>

#   the status page for monitoring the reverse proxy
<Location /apache-rproxy-status>
SetHandler server-status
</Location>

#   enable the URL rewriting engine
RewriteEngine        on
RewriteLogLevel      0

#   define a rewriting map with value-lists where
#   mod_rewrite randomly chooses a particular value
RewriteMap     server  rnd:/path/to/apache-rproxy.conf-servers

#   make sure the status page is handled locally
#   and make sure no one uses our proxy except ourself
RewriteRule    ^/apache-rproxy-status.*  -  [L]
RewriteRule    ^(http|ftp)://.*          -  [F]

#   now choose the possible servers for particular URL types
RewriteRule    ^/(.*.(cgi|shtml))$  to://${server:dynamic}/$1  [S=1]
RewriteRule    ^/(.*)$               to://${server:static}/$1  

#   and delegate the generated URL by passing it
#   through the proxy module
RewriteRule    ^to://([^/]+)/(.*)    http://$1/$2   [E=SERVER:$1,P,L]

#   and make really sure all other stuff is forbidden
#   when it should survive the above rules...
RewriteRule    .*                    -              [F]

#   enable the Proxy module without caching
ProxyRequests        on
NoCache              *

#   setup URL reverse mapping for redirect reponses
ProxyPassReverse  /  http://www1.foo.dom/
ProxyPassReverse  /  http://www2.foo.dom/
ProxyPassReverse  /  http://www3.foo.dom/
ProxyPassReverse  /  http://www4.foo.dom/
ProxyPassReverse  /  http://www5.foo.dom/
ProxyPassReverse  /  http://www6.foo.dom/

##
##  apache-rproxy.conf-servers -- Apache/mod_rewrite selection table
##

#   list of backend servers which serve static
#   pages (HTML files and Images, etc.)
static    www1.foo.dom|www2.foo.dom|www3.foo.dom|www4.foo.dom

#   list of backend servers which serve dynamically
#   generated page (CGI programs or mod_perl scripts)
dynamic   www5.foo.dom|www6.foo.dom


«Ø¥ß·sªºÀɮ׫¬ºA¤ÎªA°È
´y­z:
§A¥i¦bºô¤W§ä¨ì¤j¶qµØÄRªºCGIµ{¦¡¡A¦ý¤S¦]³o¨ÇCGIªºÁ}Ãø¥Îªk¡A«Ü¦h¤H³£¤£Ä@·N¨Ï¥Î¡A¬Æ¦ÜApache Action HandlerªºMIMEÃþ«¬¥çOn the net there are a lot of nifty CGI programs. But their usage is usually boring, so a lot of webmaster don't use them. Even Apache's Action handler feature for MIME-types is only appropriate when the CGI programs don't need special URLs (actually PATH_INFO and QUERY_STRINGS) as their input. First, let us configure a new file type with extension .scgi (for secure CGI) which will be processed by the popular cgiwrap program. The problem here is that for instance we use a Homogeneous URL Layout (see above) a file inside the user homedirs has the URL /u/user/foo/bar.scgi. But cgiwrap needs the URL in the form /~user/foo/bar.scgi/. The following rule solves the problem: RewriteRule ^/[uge]/([^/]+)/.www/(.+).scgi(.*) ...
... /internal/cgi/user/cgiwrap/~$1/$2.scgi$3  [NS,T=application/x-http-cgi]


Or assume we have some more nifty programs: wwwlog (which displays the access.log for a URL subtree and wwwidx (which runs Glimpse on a URL subtree). We have to provide the URL area to these programs so they know on which area they have to act on. But usually this ugly, because they are all the times still requested from that areas, i.e. typically we would run the swwidx program from within /u/user/foo/ via hyperlink to

/internal/cgi/user/swwidx?i=/u/user/foo/
which is ugly. Because we have to hard-code both the location of the area and the location of the CGI inside the hyperlink. When we have to reorganise or area, we spend a lot of time changing the various hyperlinks.

Solution:
The solution here is to provide a special new URL format which automatically leads to the proper CGI invocation. We configure the following: RewriteRule   ^/([uge])/([^/]+)(/?.*)/*  /internal/cgi/user/wwwidx?i=/$1/$2$3/
RewriteRule   ^/([uge])/([^/]+)(/?.*):log /internal/cgi/user/wwwlog?f=/$1/$2$3


Now the hyperlink to search at /u/user/foo/ reads only

HREF=&quot;*&quot;
which internally gets automatically transformed to

/internal/cgi/user/wwwidx?i=/u/user/foo/
The same approach leads to an invocation for the access log CGI program when the hyperlink :log gets used.

From Static to Dynamic
Description:
How can we transform a static page foo.html into a dynamic variant foo.cgi in a seemless way, i.e. without notice by the browser/user.
Solution:
We just rewrite the URL to the CGI-script and force the correct MIME-type so it gets really run as a CGI-script. This way a request to /~quux/foo.html internally leads to the invokation of /~quux/foo.cgi. RewriteEngine  on
RewriteBase    /~quux/
RewriteRule    ^foo.html$  foo.cgi  [T=application/x-httpd-cgi]


On-the-fly Content-Regeneration
Description:
Here comes a really esoteric feature: Dynamically generated but statically served pages, i.e. pages should be delivered as pure static pages (read from the filesystem and just passed through), but they have to be generated dynamically by the webserver if missing. This way you can have CGI-generated pages which are statically served unless one (or a cronjob) removes the static contents. Then the contents gets refreshed.
Solution:
This is done via the following ruleset: RewriteCond %{REQUEST_FILENAME}   !-s
RewriteRule ^page.html$          page.cgi   [T=application/x-httpd-cgi,L]


Here a request to page.html leads to a internal run of a corresponding page.cgi if page.html is still missing or has filesize null. The trick here is that page.cgi is a usual CGI script which (additionally to its STDOUT) writes its output to the file page.html. Once it was run, the server sends out the data of page.html. When the webmaster wants to force a refresh the contents, he just removes page.html (usually done by a cronjob).

Document With Autorefresh
Description:
Wouldn't it be nice while creating a complex webpage if the webbrowser would automatically refresh the page every time we write a new version from within our editor? Impossible?
Solution:
No! We just combine the MIME multipart feature, the webserver NPH feature and the URL manipulation power of mod_rewrite. First, we establish a new URL feature: Adding just :refresh to any URL causes this to be refreshed every time it gets updated on the filesystem. RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1


Now when we reference the URL

/u/foo/bar/page.html:refresh
this leads to the internal invocation of the URL

/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
The only missing part is the NPH-CGI script. Although one would usually say &quot;left as an exercise to the reader&quot; ;-) I will provide this, too.

#!/sw/bin/perl
##
##  nph-refresh -- NPH/CGI script for auto refreshing pages
##  Copyright &copy; 1997 Ralf S. Engelschall, All Rights Reserved.
##
$| = 1;

#   split the QUERY_STRING variable
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $name =~ tr/A-Z/a-z/;
    $name = 'QS_' . $name;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
    eval &quot;$$name = &quot;$value&quot;&quot;;
}
$QS_s = 1 if ($QS_s eq '');
$QS_n = 3600 if ($QS_n eq '');
if ($QS_f eq '') {
    print &quot;HTTP/1.0 200 OKn&quot;;
    print &quot;Content-type: text/htmlnn&quot;;
    print &quot;<b>ERROR</b>: No file givenn&quot;;
    exit(0);
}
if (! -f $QS_f) {
    print &quot;HTTP/1.0 200 OKn&quot;;
    print &quot;Content-type: text/htmlnn&quot;;
    print &quot;<b>ERROR</b>: File $QS_f not foundn&quot;;
    exit(0);
}

sub print_http_headers_multipart_begin {
    print &quot;HTTP/1.0 200 OKn&quot;;
    $bound = &quot;ThisRandomString12345&quot;;
    print &quot;Content-type: multipart/x-mixed-replace;boundary=$boundn&quot;;
    &print_http_headers_multipart_next;
}

sub print_http_headers_multipart_next {
    print &quot;n--$boundn&quot;;
}

sub print_http_headers_multipart_end {
    print &quot;n--$bound--n&quot;;
}

sub displayhtml {
    local($buffer) = @_;
    $len = length($buffer);
    print &quot;Content-type: text/htmln&quot;;
    print &quot;Content-length: $lennn&quot;;
    print $buffer;
}

sub readfile {
    local($file) = @_;
    local(*FP, $size, $buffer, $bytes);
    ($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
    $size = sprintf(&quot;%d&quot;, $size);
    open(FP, &quot;<$file&quot;);
    $bytes = sysread(FP, $buffer, $size);
    close(FP);
    return $buffer;
}

$buffer = &readfile($QS_f);
&print_http_headers_multipart_begin;
&displayhtml($buffer);

sub mystat {
    local($file) = $_[0];
    local($time);

    ($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
    return $mtime;
}

$mtimeL = &mystat($QS_f);
$mtime = $mtime;
for ($n = 0; $n < $QS_n; $n++) {
    while (1) {
        $mtime = &mystat($QS_f);
        if ($mtime ne $mtimeL) {
            $mtimeL = $mtime;
            sleep(2);
            $buffer = &readfile($QS_f);
            &print_http_headers_multipart_next;
            &displayhtml($buffer);
            sleep(5);
            $mtimeL = &mystat($QS_f);
            last;
        }
        sleep($QS_s);
    }
}

&print_http_headers_multipart_end;

exit(0);

##EOF##
Mass Virtual Hosting
Description:
The <VirtualHost> feature of Apache is nice and works great when you just have a few dozens virtual hosts. But when you are an ISP and have hundreds of virtual hosts to provide this feature is not the best choice.
Solution:
To provide this feature we map the remote webpage or even the complete remote webarea to our namespace by the use of the Proxy Throughput feature (flag [P]): ##
##  vhost.map
##
www.vhost1.dom:80  /path/to/docroot/vhost1
www.vhost2.dom:80  /path/to/docroot/vhost2
     :
www.vhostN.dom:80  /path/to/docroot/vhostN

##
##  httpd.conf
##
    :
#   use the canonical hostname on redirects, etc.
UseCanonicalName on

    :
#   add the virtual host in front of the CLF-format
CustomLog  /path/to/access_log  &quot;%{VHOST}e %h %l %u %t &quot;%r&quot; %>s %b&quot;
    :

#   enable the rewriting engine in the main server
RewriteEngine on

#   define two maps: one for fixing the URL and one which defines
#   the available virtual hosts with their corresponding
#   DocumentRoot.
RewriteMap    lowercase    int:tolower
RewriteMap    vhost        txt:/path/to/vhost.map

#   Now do the actual virtual host mapping
#   via a huge and complicated single rule:
#
#   1. make sure we don't map for common locations
RewriteCond   %{REQUEST_URI}  !^/commonurl1/.*
RewriteCond   %{REQUEST_URI}  !^/commonurl2/.*
    :
RewriteCond   %{REQUEST_URI}  !^/commonurlN/.*
#
#   2. make sure we have a Host header, because
#      currently our approach only supports
#      virtual hosting through this header
RewriteCond   %{HTTP_HOST}  !^$
#
#   3. lowercase the hostname
RewriteCond   ${lowercase:%{HTTP_HOST}|NONE}  ^(.+)$
#
#   4. lookup this hostname in vhost.map and
#      remember it only when it is a path
#      (and not &quot;NONE&quot; from above)
RewriteCond   ${vhost:%1}  ^(/.*)$
#
#   5. finally we can map the URL to its docroot location
#      and remember the virtual host for logging puposes
RewriteRule   ^/(.*)$   %1/$1  [E=VHOST:${lowercase:%{HTTP_HOST}}]
    :


Access Restriction
Blocking of Robots
Description:
How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file containing entries of the &quot;Robot Exclusion Protocol&quot; is typically not enough to get rid of such a robot.
Solution:
We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory indexed area where the robot traversal would create big server load). We have to make sure that we forbid access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough. This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header information. RewriteCond %{HTTP_USER_AGENT}   ^NameOfBadRobot.*      
RewriteCond %{REMOTE_ADDR}       ^123.45.67.[8-9]$
RewriteRule ^/~quux/foo/arc/.+   -   [F]


Blocked Inline-Images
Description:
Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because it adds useless traffic to our server.
Solution:
While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser sends a HTTP Referer header. RewriteCond %{HTTP_REFERER} !^$                                 
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
RewriteRule .*.gif$        -                                    [F]

RewriteCond %{HTTP_REFERER}         !^$                                 
RewriteCond %{HTTP_REFERER}         !.*/foo-with-gif.html$
RewriteRule ^inlined-in-foo.gif$   -                        [F]


Host Deny
Description:
How can we forbid a list of externally configured hosts from using our server?
Solution:
For Apache >= 1.3b6: RewriteEngine on
RewriteMap    hosts-deny  txt:/path/to/hosts.deny
RewriteCond   ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond   ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND
RewriteRule   ^/.*  -  [F]


For Apache <= 1.3b6:

RewriteEngine on
RewriteMap    hosts-deny  txt:/path/to/hosts.deny
RewriteRule   ^/(.*)$ ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND}/$1
RewriteRule   !^NOT-FOUND/.* - [F]
RewriteRule   ^NOT-FOUND/(.*)$ ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND}/$1
RewriteRule   !^NOT-FOUND/.* - [F]
RewriteRule   ^NOT-FOUND/(.*)$ /$1

##
##  hosts.deny
##
##  ATTENTION! This is a map, not a list, even when we treat it as such.
##             mod_rewrite parses it for key/value pairs, so at least a
##             dummy value &quot;-&quot; must be present for each entry.
##

193.102.180.41 -
bsdti1.sdm.de  -
192.76.162.40  -


URL-Restricted Proxy
Description:
How can we restrict the proxy to allow access to a configurable set of internet sites only? The site list is extracted from a prepared bookmarks file.
Solution:
We first have to make sure mod_rewrite is below(!) mod_proxy in the Configuration file when compiling the Apache webserver (or in the AddModule list of httpd.conf in the case of dynamically loaded modules), as it must get called _before_ mod_proxy.
For simplicity, we generate the site list as a textfile map (but see the mod_rewrite documentation for a conversion script to DBM format). A typical Netscape bookmarks file can be converted to a list of sites with a shell script like this:

#!/bin/sh
cat ${1:-~/.netscape/bookmarks.html} |
tr -d '15' | tr '[A-Z]' '[a-z]' | grep href=&quot; |
sed -e '/href=&quot;file:/d;' -e '/href=&quot;news:/d;'
    -e 's|^.*href=&quot;[^:]*://([^:/&quot;]*).*$|1 OK|;'
    -e '/href=&quot;/s|^.*href=&quot;([^:/&quot;]*).*$|1 OK|;' |
sort -u


We redirect the resulting output into a text file called goodsites.txt. It now looks similar to this:

www.apache.org OK
xml.apache.org OK
jakarta.apache.org OK
perl.apache.org OK
...


We reference this site file within the configuration for the VirtualHost which is responsible for serving as a proxy (often not port 80, but 81, 8080 or 8008).

<VirtualHost *:8008>
  ...
  RewriteEngine   On
  # Either use the (plaintext) allow list from goodsites.txt
  RewriteMap      ProxyAllow   txt:/usr/local/apache/conf/goodsites.txt
  # Or, for faster access, convert it to a DBM database:
  #RewriteMap     ProxyAllow   dbm:/usr/local/apache/conf/goodsites
  # Match lowercased hostnames
  RewriteMap      lowercase    int:tolower
  # Here we go:
  # 1) first lowercase the site name and strip off a :port suffix
  RewriteCond  ${lowercase:%{HTTP_HOST}}    ^([^:]*).*$
  # 2) next look it up in the map file.
  #    &quot;%1&quot; refers to the previous regex.
  #    If the result is &quot;OK&quot;, proxy access is granted.
  RewriteCond  ${ProxyAllow:%1|DENY}        !^OK$          [NC]
  # 3) Disallow proxy requests if the site was _not_ tagged &quot;OK&quot;:
  RewriteRule  ^proxy:                      -              [F]
  ...
</VirtualHost>


Proxy Deny
Description:
How can we forbid a certain host or even a user of a special host from using the Apache proxy?
Solution:
We first have to make sure mod_rewrite is below(!) mod_proxy in the Configuration file when compiling the Apache webserver. This way it gets called _before_ mod_proxy. Then we configure the following for a host-dependend deny... RewriteCond %{REMOTE_HOST} ^badhost.mydomain.com$
RewriteRule !^http://[^/.].mydomain.com.*  - [F]


...and this one for a user@host-dependend deny:

RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST}  ^badguy@badhost.mydomain.com$
RewriteRule !^http://[^/.].mydomain.com.*  - [F]


Special Authentication Variant
Description:
Sometimes a very special authentication is needed, for instance a authentication which checks for a set of explicitly configured users. Only these should receive access and without explicit prompting (which would occur when using the Basic Auth via mod_access).
Solution:
We use a list of rewrite conditions to exclude all except our friends: RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend1@client1.quux-corp.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp.com$
RewriteRule ^/~quux/only-for-friends/      -                                 [F]


Referer-based Deflector
Description:
How can we program a flexible URL Deflector which acts on the &quot;Referer&quot; HTTP header and can be configured with as many referring pages as we like?
Solution:
Use the following really tricky ruleset... RewriteMap  deflector txt:/path/to/deflector.map

RewriteCond %{HTTP_REFERER} !=&quot;&quot;
RewriteCond ${deflector:%{HTTP_REFERER}} ^-$
RewriteRule ^.* %{HTTP_REFERER} [R,L]

RewriteCond %{HTTP_REFERER} !=&quot;&quot;
RewriteCond ${deflector:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^.* ${deflector:%{HTTP_REFERER}} [R,L]


... in conjunction with a corresponding rewrite map:

##
##  deflector.map
##

http://www.badguys.com/bad/index.html    -
http://www.badguys.com/bad/index2.html   -
http://www.badguys.com/bad/index3.html   http://somewhere.com/


This automatically redirects the request back to the referring page (when &quot;-&quot; is used as the value in the map) or to a specific URL (when an URL is specified in the map as the second argument).

Other
External Rewriting Engine
Description:
A FAQ: How can we solve the FOO/BAR/QUUX/etc. problem? There seems no solution by the use of mod_rewrite...
Solution:
Use an external rewrite map, i.e. a program which acts like a rewrite map. It is run once on startup of Apache receives the requested URLs on STDIN and has to put the resulting (usually rewritten) URL on STDOUT (same order!). RewriteEngine on
RewriteMap    quux-map       prg:/path/to/map.quux.pl
RewriteRule   ^/~quux/(.*)$  /~quux/${quux-map:$1}

#!/path/to/perl

#   disable buffered I/O which would lead
#   to deadloops for the Apache server
$| = 1;

#   read URLs one per line from stdin and
#   generate substitution URL on stdout
while (<>) {
    s|^foo/|bar/|;
    print $_;
}


This is a demonstration-only example and just rewrites all URLs /~quux/foo/... to /~quux/bar/.... Actually you can program whatever you like. But notice that while such maps can be used also by an average user, only the system administrator can define it.


--------------------------------------------------------------------------------

Apache HTTP Server Version 1.3
                     
§@ªÌ: FIEND    ®É¶¡: 2003-3-1 00:33     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!

·sªº Apache ¤w                    
§@ªÌ: FIEND    ®É¶¡: 2003-3-1 00:38     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!



¥ÎApache¤Ï¦V¥N²z³]¸m¹ï¥~ªºWWW©M¤å¥óªA°È¾¹
http://www.eschool.com.cn/ §@ªÌ:§dªü«F (2001-05-01 16:30:19)
²¤¶¡G¤@¥x¾÷¾¹¥Î±M½u±µ¤JInternet§@¬°¨¾¤õÀð¡A¦b¤º³¡ºô¬q¤W¦³¤@¥xWWWªA°È¾¹¡@¡]Redhat¡@6.1,Apache¡@1.3.9¡^§Æ±æ³o¥x¾÷¾¹¯à¹ï¥~´£¨ÑWWWªA°È¾¹©M°ò¤_apacheªº¤å¥óªA°È¡C¨Ñ¥~³¡¥@¬É¤½¦@³X°ÝWWWªA°È¾¹¡A©ÎªÌ¥~¦a¤À¤½¥q¤U¸ü»Ý­nªº¤å¥ó¡C¡@

ÀuÂI¡G¡@¤º³¡ªºWWWªA°È¾¹©M¤å¥óªA°È§¹¥þ»P¥~³¡¥@¬É¹j¶}¡A¤£ª½±µ³s±µ¨ì¥~³¡¡A³q¹L¨¾¤õÀð¤W¹B¦æªºApacheªA°È´£¨Ñ¹ï¤º³¡ªº¥N²z³X°Ý¡A¼W±j¤F¦w¥þ©Ê¡A¦P®É¦b¨¾¤õÀð¤W¹B¦æªºApacheªA°È¹B¥Î°ò¤_¦W¦rªºµêÀÀ¥D¾÷§Þ¥º¡A¨Ï±o¨¾¤õÀð¤Wªº¥D­¶¤£·|³Q³X°Ý¨ì¡C²Å¦X¤F§@¬°¨¾¤õÀð­n¨D¹B¦æªA°È¶V¤Ö¶V¦w¥þªº­ã«h¡C¡@

¹ê²{¤èªk¡G¦b¤º³¡ºô¬q¤WªºApacheªA°È¾¹¡]192.168.11.2¡^¦s©ñªº¬O¤½¥q¥D­¶¡A¨Ñ¤º³¡©M¥~³¡¥Î¤á¤½¦@³X°Ý¡A¦}³]¸m/home/ftp/pub¥Ø¿ý¬°¤å¥ó¦s©ñ°Ï°ì¡A¥Îhttp://download.yourdomain.com/pub/¨Ó³X°Ý¡C¦b¨¾¤õÀð¤W³]¸mapache¤Ï¦V¥N²z§Þ¥º¡A¥Ñ¨¾¤õÀð¥N²z¹ï¤º³¡ºô¬q¤Wªº³X°Ý¡C¡@

¨BÆJ¡G¡@
¤@.¡@¤º³¡ºô¬q¤WªºApacheªA°È¾¹³]¸m¡@
¡@¡@apacheªö¥ÎÀq»{°t¸m¡C¥D¥Ø¿ý¬°/home/httpd/html,¥D¾÷°ì¦W¬°¡@sun.yourdomain.com,¥B§O¦W¨ìwww.yourdomain.com,¡@¦}¥B³]¸msrm.conf¥[¤@¦æ§O¦W©w¸q¦p¤U¡G¡@
Alias¡@/pub¡@/home/ftp/pub/¡@

¥B§ó§ïÀq»{À³¥Îµ{§ÇÃþ«¬©w¸q¦p¤U¡G¡@
DefaultType¡@application/octet-stream¡@

³Ì¦Z¦b/etc/httpd/conf/access.conf¤¤¼W¥[¤@¶µ©w¸q¡@

Options¡@Indexes¡@
AllowOverride¡@AuthConfig¡@
order¡@allow,deny¡@
allow¡@from¡@all¡@

ª`¡GOptions¡@Indexes¤¹³¦b§ä¤£¨ìindex.html¤å¥óªº±¡ªp¤U¤¹³¦C¥X¥Ø¿ý/¤å¥ó¦Cªí¡CAllowOverride¡@AuthConfig¤¹³°µ°ò¥»ªº¥Î¤á¦W©M¤f¥OÅçµý¡C³o¼Ëªº¸Ü¡A§A»Ý­n¦b/home/ftp/pub¥Ø¿ý¤U©ñ¤J.htaccess¡A¤º®e¦p¤U¡G¡@
-------¡@
[root@shopu¡@pub]#¡@more¡@.htaccess¡@
AuthName¡@Branch¡@Office¡@Public¡@Software¡@Download¡@Area¡@
AuthType¡@Basic¡@
AuthUserFile¡@/etc/.usrpasswd¡@
require¡@valid-user¡@
------¡@
µM¦Z¥Î#htpasswd¡@-c¡@/etc/.usrpasswd¡@user1¡@
¤À§O³Ð«Ø¤£¦Pªº¤¹³³X°Ý/pub¤U¤å¥óªA°Èªº¥~³¡¥Î¤á¦W©M¤f¥O¡C¡@


¤G.¡@¨¾¤õÀð¤W¤Ï¦V¥N²z°t¸m¡G¡@
¡@¡@¥[¤U­±ªº¦æ¨ì/etc/httpd/conf/httpd.conf¡@
NameVirtualHost¡@1.2.3.4¡@

#¡@1.2.3.4¬O¨¾¤õÀð¥~³¡ºô¥dªº¤¬Ápºô¤W¥Ã¤[IP¦a§}¡@


servername¡@www.yourdomain.com¡@
errorlog¡@/var/log/httpd/error_log¡@
transferlog¡@/var/log/httpd/access_log¡@
rewriteengine¡@on¡@
proxyrequests¡@off¡@
usecanonicalname¡@off¡@
rewriterule¡@^/(.*)$¡@http://192.168.11.2/$1¡@[P,L]¡@



servername¡@download.yourdomain.com¡@
errorlog¡@/var/log/httpd/download/error_log¡@
transferlog¡@/var/log/httpd/download/access_log¡@
rewriteengine¡@on¡@
proxyrequests¡@off¡@
usecanonicalname¡@off¡@
rewriterule¡@^/(.*)$¡@http://192.168.11.2/$1¡@[P,L]¡@


ª`¡G³]¸m¨¾¤õÀð¤WªºDNS¡AÅýdownload.yourdomain.com©Mwww.yourdomain.com³£«ü¦V¨¾¤õÀ𪺥~³¡ºô¥d¦a§}¡C¥Îwww.yourdomain.com¨¾°Ý§Aªº¤½¥q¥D­¶¡A¡@¥Îhttp://download.yourdomain.com/pub/³X°Ý§Aªº¤½¦@¤å¥ó¤U¸ü°Ï¡C¡@


¡@¡@§A»Ý­n¦b¤º³¡ºô¬qªºapache¥D¾÷¤W«Ø¥ß¥Ø¿ý/var/log/httpd/download/¥Ø¿ý¡A§_«h·|¥X¿ù¡C¥t¥~¡A§A¤]¥i¥H³]¸m¨¾¤õÀð¥D¾÷¤Wªº/home/httpd/html/index.htmlªºÄݩʬ°750ªý¤î³X°Ý¡A¸U¤@¥~³¡¥Î¤á¯à³X°Ý¨ì¨¾¤õÀð¤WªºApache¥D­¶ªº¸Ü¡C¡@
(http://www.fanqiang.com)     ¶i¤J¡iUNIX½×¾Â¡j  

--------------------------------------------------------------------------------

¬ÛÃö¤å³¹  



===§ó¦h¬ÛÃö===
  


¡¹  ¼Ô±j¨î§@ Åwªï¤À¨É  ¡¹
                     
§@ªÌ: FIEND    ®É¶¡: 2003-3-1 00:39     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!




­º­¶ > À³¥Î§Þ¥º > Apache > ¥¿¤å

¦p¦ó³W¦E¤@­Ó°ª®e¶qªºApacheªA°È¾¹¡H
http://www.linuxforum.net §dªü«F (2001-04-21 17:40:21)
¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@
¬°¤F³W¦E¤@­Ó°ª®e¶qªºWEBªA°È¾¹¡A§Ú­Ì¤À¦¨¥H¤UÀô¸`¨Ó°µ¡G

¤@¡Gºôµ¸Àô¹Ò

¡@¡@¡@¡@¡@¡@¡@¡@¢w¢w¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¢w¢w
¡@¡@¡@¡@¡@¡@¡@|¡@¡@¡@|(eth0:192.168.11.8)¡@¡@¡@¡@¡@¡@¡@|¡@¡@|(eth0:a.b.c.d)
¡@¡@¡@¡@¡@¡@¡@|¡@A¡@|¢w¢w¢w¢w¢w¢w--------------|¡@B|------------->ISP¡@
¡@¡@¡@¡@¡@¡@¡@¡@¢w¢w¡@¡@¡@¡@¡@¡@¡@¡@(eth1:192.168.11.5)¢w¢w
¡@¡@¡@web.company.com¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@firewall.company.com


A¬O§½°ìºô¤º³¡ªº¤@¥xWEBªA°È¾¹¡A¦w¸ËRedhat¡@Linux¡@6.X,½sĶApache+PHP4+MySQL
B¬O¤½¥q¨¾¤õÀð¡A¥~³¡¦a§}¬°a.b.c.d¡A¬O³q¦VInternetªº°ß¤@¸ô®|¡CB¤W¤]¹B¦æApache
°µ¤Ï¦V¥N²z¨ì¤º³¡¾÷¾¹B¡C°²³]¤½¥qªº°ì¦W¬°@company.com¡AB¬O¸Ó°ìªº°ì¦WªA°È¾¹¡C

¤G¡GWEB¥Ø¿ýªº²Õ´µ²ºc
§Ú­Ì­p¦E§âWEBªA°È¾¹¼Æ¾Ú¤å¥ó¸m¤_¤@³æ¿Wªº¥Ø¿ý/www¤U­±¡A¦A¦b¨ä¤U­±«Ø¥ß¬ÛÀ³ªº
¤l¥Ø¿ý¡A¦pªG§Ú­Ì­p¦E³]¸mWEBªA°È¾¹web.company.com¡A«h«Ø¥ß¥Ø¿ý
/www/web.company.com¡@,µ²ºc¦p¤U¡G

/www/web.company.com/public/htdocs
¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@/cgi-bin
/www/web.company.com/staging/htdocs
¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@/cgi-bin
/www/web.company.com/developer/htdocs
¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@/cgi-bin
¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@¡@
¤T:¡@³X°Ý¤èªk»PµêÀÀ¥D¾÷
¹ïstaging©Mdeveloper¥Ø¿ý¥Î°ò¤_ºÝ¤fªºµêÀÀ¥D¾÷¨Ó³X°Ý¡A¤À§O¹ïÀ³ºÝ¤f81,82¡C
¤U­±¬Oapacheªº°t¸m¤å¥ó/usr/local/apache/conf/httpd.conf¤¤µêÀÀ¥D¾÷³¡¤Àªº
°t¸m¡G
Listen¡@80
Listen¡@192.168.11.8:81
Listen¡@192.168.11.8:82

¡qVirtualHost¡@192.168.11.8:81>
documentroot¡@/www/web.company.com/staging/htdocs/
scriptalias¡@/cgi-bin¡@/www/web.company.com/staging/cgi-bin/
transferlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/usr/local/apache/logs/web/staging/%Y/%m/%d/access_log&quot;
errorlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/usr/local/apache/logs/web/staging/%Y/%m/%d/error_log&quot;
¡q/VirtualHost>

¡qVirtualHost¡@192.168.11.8:82>
documentroot¡@/www/web.company.com/developer/htdocs/
scriptalias¡@/cgi-bin¡@/www/web.company.com/developer/cgi-bin/
transferlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/usr/local/apache/logs/web/developer/%Y/%m/%d/access_log&quot;
errorlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/usr/local/apache/logs/web/developer/%Y/%m/%d/error_log&quot;
¡q/VirtualHost>

ª`¡G¤W­±¬O°ò¤_ºÝ¤fªºµêÀÀ¥D¾÷³]¸m¡A­n³X°Ý´ú¸ÕªA°È¾¹¡A¥Îhttp://web.company.com:81/
¶}µoªA°È¾¹¥Îhttp://web.company.com:82/
¤W­±ªºtransferlog¡@and¡@errorlog¥Î¤F¤£¬OÀq»{ªº®æ¦¡¡A¦Ó¬OApacheºô¯¸¤W«ØÄ³ªº³oºØ¨C¤Ñ
¤@­Ó¤å¥óªº¦~/¤ë/¤é®æ¦¡¡A¥i±qhttp://www.ford-mason.co.uk/resources/cronolog/¤U¸ü½sĶ
¦Z¦w¸Ë¦b/usr/local/apache/bin/cronolog,¥i¬d¬ÝApacheºô¯¸Àò±o§ó¦h«H®§¡C
http://httpd.apache.org/docs/misc/FAQ.html#rotate


¦pÁÙ¦³¨ä¥¦¥D­¶»Ý­n¦b¦¹ªA°È¾¹¤WªA°È¡A¦p¦b/www¤U¦A³Ð«Ø¤l¥Ø¿ýhr.company.com(¤H¨Æ³¡ªù)
¡A¥i¬°¥D¾÷A³Ð«ØIP§O¦W¡A¦p192.168.11.9¡A¦A°µ¦P¼Ëªº°ò¤_ºÝ¤fªºµêÀÀ¥D¾÷³]¸m

¤T:­Ó¤H¥D­¶ªº±¡ªp
°²©wApache¥H¥Î¤á²Õ¨­¥÷nobody¹B¦æ¡A¥B¥Î¤á¥D¥Ø¿ý¬°/home/jephe¡A«h¦b¦¹¥Ø¿ý¤U³Ð«Ø¥Ø¿ý
public_html
a.³]¸m¥Î¤á¥D¥Ø¿ý/home/jephe­nµ¹nobody²Õ¥HŪ©M°õ¦æªºÅv­­
¡@¡@¡@chmod¡@750¡@-R¡@/home/jephe
b.³]¸m¥Î¤á¥D¥Ø¿ý/home/jephe¤Upublic_html¥Ø¿ýªºÅv­­
¡@¡@¡@chmod¡@-R¡@2770¡@/home/jephe/public_html

c.³]¸m¥Î¤á¥D¥Ø¿ýªº¾Ö¦³ªÌ
¡@¡@¡@chown¡@-R¡@jephe.nobody¡@/home/jephe/public_html
¥Î¤á¥iFTP¤W¶Ç¥D­¶¤å¥ó¦Ü¦Û¤vªº¥Ø¿ý¤¤¡A­n³]¸m/etc/inetd.conf¤¤ªºFTP¤W¸üªºumaskÀq»{­È
¬°u002¡A
ftp¡@¡@¡@¡@¡@stream¡@¡@tcp¡@¡@¡@¡@¡@nowait¡@¡@root¡@¡@¡@¡@/usr/sbin/tcpd¡@¡@in.ftpd¡@-l¡@-a¡@-u002
µM¦Z¥Îkillall¡@-HUP¡@inetd¥Í®Ä¡C
³Ì¦Z¥Îhttp://web.company.com/~jephe/¡@³X°Ý­Ó¤H¥D­¶¡C

¥|:¨¾¤õÀð¾÷¾¹B¤WªºApache¤Ï¦V¥N²z

³]¸m¦p¤U¡G

NameVirtualHost¡@a.b.c.d

¡qVirtualHost¡@a.b.c.d>
servername¡@web.company.com
errorlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/var/log/httpd/web/%Y/%m/%d/error_log&quot;
transferlog¡@&quot;|/usr/local/apache/bin/cronolog¡@/var/log/httpd/web/%Y/%m/%d/access_log&quot;
rewriteengine¡@on
rewriterule¡@^(/.*)$¡@http://192.168.11.8/$1¡@[P,L]
proxyrequests¡@off
¡q/VirtualHost>

¤­:³Æ¥÷
¥ÎRsync³Æ¥÷¥D¥Ø¿ý/www/web.company.com/public/htdocs¾ã­Ó¥Ø¿ý¡AÃö¤_¦p¦óÀ³¥ÎRSYNC¡A°Ñ¨£
¤å³¹îPµÑ¤¤ªº¨ä¥¦¤å³¹¡A¥D­¶¦brsync.samba.org



Jephe
(http://www.fanqiang.com)     ¶i¤J¡iUNIX½×¾Â¡j  

--------------------------------------------------------------------------------

¬ÛÃö¤å³¹  



  


¡¹  ¼Ô±j¨î§@ Åwªï¤À¨É  ¡¹                     
§@ªÌ: FIEND    ®É¶¡: 2003-3-1 00:43     ¼ÐÃD: ¤@­Ó¤£¥i¤£ª¾ªº¼Ò²Õ Æg!!!!


Apache ­«¼g³W«hªº±`¨£À³¥Î (rewrite)
¥»¤å¥X¦Û:http://www.linuxforum.net §@ªÌ:§dªü«F Jephe wu (2001-09-05 08:00:00)
¤@:¥Øªº  

      ¥»¤å¦®¦b´£¨Ñ¦p¦ó¥ÎApache­«¼g³W«h¨Ó¸Ñ¨M¤@¨Ç±`¨£ªºURL­«¼g¤èªkªº°ÝÃD¡A³q¹L±`¨£ªº
      ¹ê¨Òµ¹¥Î¤á¤@¨Ç¨Ï¥Î­«¼g³W«hªº°ò¥»¤èªk©M½u¯Á¡C  

      ¤G:¬°¤°¤»Ý­n¥Î­«¼g³W«h¡H  
      ¤@­Óºô¯¸¡A¦pªG¬Oªø´Á»Ý­n©ñ¦binternet¤W´£¨ÑªA°È¡A¥²©w·|¦³¤£Â_¦a§ó·s©MºûÅ@¡A¦pÁ{
      ®ÉÂಾ¨ì¨ä¥¦ªA°È¾¹¶i¦æºûÅ@¡A­«·s²Õ´¥Ø¿ýµ²ºc¡AÅÜ´«URL¬Æ¦Ü§ïÅܨì·sªº°ì¦Wµ¥µ¥¡A
      ¦Ó¬°¤FÅý«È¤á¤£·|¦]¦¹¨ü¨ì¥ô¦ó¼vÅT¡A³Ì¦nªº¤èªk´N¬O¨Ï¥ÎApache Rewrite Rule(­«¼g
      ³W«h)¡C  

      ¤T: ­«¼g³W«hªº§@¥Î­S³ò  
      1) ¥i¥H¨Ï¥Î¦bApache¥D°t¸m¤å¥óhttpd.conf¤¤  
      2) ¥i¥H¨Ï¥Î¦bhttpd.conf¨½©w¸qªºµêÀÀ¥D¾÷°t¸m¤¤  
      3) ¥i¥H¨Ï¥Î¦b°ò¥»¥Ø¿ýªº¸ó¶V°t¸m¤å¥ó.htaccess¤¤  

      ¥|:­«¼g³W«hªºÀ³¥Î±ø¥ó  
      ¥u¦³·í¥Î¤áªºWEB½Ð¨D³Ì²×³Q¾É¦V¨ì¬Y¥xWEBªA°È¾¹ªºApache¦Z¥x¡A«h³o¥xWEBªA°È¾¹±µ¨ü
      ¶i¨Óªº½Ð¨D¡A®Ú¾Ú°t¸m¤å¥ó¸Ó½Ð¨D¬O¥D°t¸mÁÙ¬OµêÀÀ¥D¾÷¡A¦A®Ú¾Ú¥Î¤á¦bÂsÄý¾¹¤¤½Ð¨Dªº
      URI¨Ó°t¹ï­«¼g³W«h¦}¥B®Ú¾Ú¹ê»Úªº½Ð¨D¸ô®|°t¹ï.htaccess¤¤ªº­«¼g³W«h¡C³Ì¦Z§â½Ð¨D
      ªº¤º®e¶Ç¦^µ¹¥Î¤á¡A¸ÓÅTÀ³¥i¯à¦³¨âºØ¡G  

      1) ¹ïÂsÄý¾¹½Ð¨D¤º®eªº¥~³¡­«©w¦V(Redirect)¨ì¥t¤@­ÓURL¡C  
      ÅýÂsÄý¾¹¦A¦¸¥H·sªºURIµo¥X½Ð¨D(R=301©ÎªÌR=302¡AÁ{®Éªº©Î¬O¥Ã¤[ªº­«©w¦V)  
      ¦p¡G¤@­Óºô¯¸¦³¥¿³WªºURL©M§O¦WURL¡A¹ï§O¦WURL¶i¦æ­«©w¦V¨ì¥¿³WURL¡A©ÎªÌºô¯¸§ï´«
      ¦¨¤F·sªº°ì¦W  
      «h§âªº°ì¦W­«©w¦V¨ì·sªº°ì¦W(Redirect)  

      2) ¤]¥i¯à¬O¥ÑApache¤º³¡¤l½Ð¨D¥N²z²£¥Í·sªº¤º®e°e¦^µ¹«È¤á[P,L]  
      ³o¬OApache¤º³¡®Ú¾Ú­«¼g¦ZªºURI¤º³¡³q¹L¥N²z¼Ò¶ô½Ð¨D¤º®e¦}°e¦^¤º®eµ¹«È¤á¡A¦Ó«È¤á
      ºÝÂsÄý¾¹¦}  
      ¤£ª¾¹D¡AÂsÄý¾¹¤¤ªºURI¤£·|³Q­«¼g¡C¦ý¹ê»Ú¤º®e³QApache®Ú¾Ú­«¼g³W«h¦ZªºURI±o¨ì¡C  
      ¦p¡G¦b¤½¥q¨¾¤õÀð¤W¹B¦æªºApache±Ò°Ê³oºØ¥N²z­«¼g³W«h¡A¥N²z¹ï¤º³¡ºô¬q¤WªºWEBªA°È
      ¾¹ªº½Ð¨D¡C  

      ¤­:­«¼g³W«h«ç¼Ë¤u§@¡H  
      §Ú­Ì°²©w¦b½sĶApache®É¤w¸g§âmod_rewrite½sͦ¨¼Ò¶ô¡A½T«H§Aªºhttpd.conf¤¤¦³  
      LoadModule rewrite_module libexec/mod_rewrite.so  
      ¦}¥B¦bAddmodule¤¤¦³  
      Addmodule mod_rewrite.c  
      «h¥i¥H¨Ï¥Î­«¼g³W«h¡C  
      ·í¥~³¡½Ð¨D¨Ó¨ìApache¡AApache½Õ¥Î­«¼g³W«h¤¤ªº©w¸q¨Ó­«¼g¥Ñ¥Î¤áÂsÄý¾¹«ü©w½Ð¨Dªº
      URI¡A³Ì¦Z³Q­«¼gªºURI¦pªG¬O­«©w¦V¡A«h°e¥ÑÂsÄý¾¹§@¦A¤@¦¸½Ð¨D¡Q¦pªG¬O¥N²z«h§â­«¼g
      ¦ZªºURI¥æµ¹¥N²z¼Ò¶ô½Ð¨D³Ì²×ªº¤º®e(Content),³Ì¦Z§â¤º®e°e¦^µ¹ÂsÄý¾¹¡C  

      ¤»: ¦ó®É¨Ï¥Î.htaccess¤¤ªº­«¼g³W«h©w¸q¡H  
      °²¦p§A¹ï§Aªºªººô¯¸¤º®e©Ò¦bªºªA°È¾¹¨S¦³ºÞ²z­ûÅv­­¡A©ÎªÌ§Aªººô¯¸©ñ¦bISPªºªA°È¾¹
      ¤W¦«ºÞµ¥µ¥±ø¥ó¤U¡A§AµLªk§ï¼g¥D°t¸m¤å¥ó¡AµM¦Ó§A¥i¥H¹ï§AªºWEB¯¸ÂI¤º®e©Ò¦bªº¥Ø¿ý
      ¦³¼gÅv­­¡A«h§A¥i¥H³]¸m¦Û¤vªº.htaccess  
      ¤å¥ó¹F¨ì¦P¼Ëªº¥Øªº¡C¦ý§A»Ý­n½T©w¥D°t¸m¤å¥ó¤¤¹ï§Aªººô¯¸©Ò¦bªº¥Ø¿ý©w¸q¤F¤U­±ªº¤º
      ®e:  

      Options Indexes FollowSymLinks  
      AllowOverride all  

      §_«h§Aªº.htaccess¤£·|¤u§@¡C  

      ¤C: À³¥ÎÁ|¨Ò  
      °²©wApache³Q½sͦw¸Ë¦b¥D¾÷192.168.1.56ªº/usr/local/apache/ ¥Ø¿ý¤U­±¡A§Ú­Ì½s
      Ä¶¶i¤F­«¼g©M¥N²z¼Ò¶ô¡C  

      1) ÁôÂÃApache¤Uªº¬Y­Ó¥Ø¿ý¡A¨Ï±o¹ï¸Ó¥Ø¿ýªº¥ô¦ó½Ð¨D³£­«©w¦V¨ì¥t¤@­Ó¤å¥ó¡C  

      a> httpd.confªº¹ê²{¤èªk  

      §Ú­Ì©ñ¤U­±ªº³¡¤À¨ì/usr/local/apache/conf/httpd.conf  


      options Indexes followsymlinks  
      allowoverride all  
      rewriteengine on  
      rewritebase /  
      rewriterule ^(.*)$ index.html.en [R=301]  


      ª`¡Grewriteengine on ¬°­«¼g¤ÞÀº¶}Ãö¡A¦pªG³]¬°off,«h¥ô¦ó­«¼g³W«h©w¸q±N¤£³QÀ³
      ¥Î¡A¸Ó¶}Ãöªº¥t¤@¦n³B´N¬O¦pªG¬°¤FÁ{®É®³±¼­«¼g³W«h¡A«h§ï¬°off¦A­«±Ò°ÊApache§Y
      ¥i¡A¤£¥²±N¤U­±¤@±ø±øªº­«¼g³W«hª`ÄÀ±¼¡C  
      rewritebase / ªº§@¥Î¬O¦pªG¦b¤U­±ªºrewriterule©w¸q¤¤³Q­«¼g¦Zªº³¡¤À(¦¹³B¬°¤å¥ó
      ¦Windex.html.en)«e­±¨S¦³/¡A«h¬O¬Û¹ï¥Ø¿ý¡A¬Û¹ï¤_³o­Órewritebase¦Z­±ªº©w¸q¤]´N
      ¬O/usr/local/apache/htdocs/index.html.en,§_«h¡A¦pªG¦¹³B¨S¦³rewritebase /³o
      ¤@¶µ¡A«h³Q­«¼g¦¨  
      http://192.168.1.56/usr/local/apache/htdoc...l/index.html.en ¡AÅãµM¬O
      ¤£¥¿½Tªº¡C  

      ¤£¹L³o¨½§Ú­Ì¤]¥i¥H¤£¥Îrewritebase / , ¦Ó§ï¬°  
      rewriteengine on  
      rewriterule ^(.*)$ /index.html.en [R=301]  
      ©ÎªÌ  
      rewriteengine on  
      rewriterule ^(.*)$ http://192.168.1.56/index.html.en [R=301]  

      b> .htaccessªº¹ê²{¤èªk  

      §Ú­Ì¥ý©ñ¤U­±ªº³¡¤À¨ìhttpd.conf  


      options Indexes followsymlinks  
      allowoverride all  


      µM¦Z©ñ¤U­±ªº³¡¤À¨ì/usr/local/apache/htdocs/manual/.htaccess¤¤  
      rewriteengine on  
      rewritebase /  
      rewriterule ^(.*)$ index.html.en [R=301]  

      ª`¡G¹ï¤å¥ó.htaccess©Ò§@ªº¥ô¦ó§ï°Ê¤£»Ý­n­«±Ò°ÊApache.  

      °Ý¡G­n¬O§â³o­Ómanual¥Ø¿ý­«©w¦V¨ì¥Î¤ájepheªº¦Û¤vªº¥D¥Ø¿ý©O¡H  
      ¥Î¤U­±ªº.htaccess¤è®×¡C  
      rewriteengine on  
      rewritebase /~jephe/  
      rewriterule ^(.*)$ $1 [R=301]  

      «h¹ïmanual¥Ø¿ý¤U¥ô¦ó¤å¥óªº½Ð¨D³Q­«©w¦V¨ì~jephe¥Ø¿ý¤U¬Û¦P¤å¥óªº½Ð¨D¡C  

      2) Âà´«www.username.domain.comªº¹ï¤_usernameªº¥D­¶½Ð¨D¬°
      www.domain.com/username  

      ¹ï¤_HTTP/1.1ªº½Ð¨D¥]¬A¤@­ÓHost: HTTPÀY¡A§Ú­Ì¯à¥Î¤U­±ªº³W«h¶°­«¼g  
      http://www.username.domain.com/anypath ¨ì /home/username/anypath  

      Rewriteengine on  
      rewritecond %{HTTP_HOST} ^www.[^.]+.host.com$  
      rewriterule ^(.+) %{HTTP_HOST}$1 [C]  
      rewriterule ^www.([^.]+).host.com(.*) /home/$1$2  

      ª`¡G  
      rewritecond ±ø¥ó­«¼g³W«h¡A·íº¡¨¬¦Z­±©w¸qªº±ø¥ó¦Z¤~·|À³¥Î¤U­±ªº­«¼g³W«h¡A
      rewritecond¦³¦UºØÅܶq  
      ¡A½Ð¬d¾¬ÛÃö¤åÀÉ¡C  

      3) ¨¾¤õÀð¤Wªº­«¼g³W«h¥N²z¤º³¡ºô¬q¤WªA°È¾¹ªº½Ð¨D¡C  

      NameVirtualhost 1.2.3.4  


      servername www.domain.com  
      rewriteengine on  
      proxyrequest on  
      rewriterule ^/(.*)$ http://192.168.1.3/$1 [P,L]  


      ª`¡G·í¥~³¡ÂsÄý¾¹½Ð¨Dwww.domain.com®É³Q¸ÑªR¨ìIP¦a§}1.2.3.4 ,Apache ¥æ¥X
      mod_rewrite³B²zÂà´«¦¨  
      http://192.168.1.3/$1¦Z¦A¥æ¥Ñ¥N²z¼Ò¶ômod_p...^¥Î¤áªºÂsÄý¾¹¡C


      4) °ò¥»¹w¥ý³]©wªºÂà´«MAPªí¶i¦æ­«¼g rewritemap  

      Âà´«www.domain.com/{countrycode}/anypath ¨ìMapªí¤¤³W©wªºURI,¤W­±¬OµêÀÀ¥D¾÷
      ¤¤ªº©w¸q  

      rewritelog /usr/local/apache/logs/rewrite.log  
      rewriteloglevel 9  

      rewriteengine on  
      proxyrequest on  
      rewritemap sitemap txt:/usr/local/apache/conf/rewrite.map  
      rewriterule ^/([^/]+)+/(.*)$ http://%{REMOTE_HOST}::$1 [C]  
      rewriterule (.*):[a-z]+)$ ${sitemap:$2|http://h.i.j.k/} [R=301,L]  

      ¤å¥ó/usr/local/apache/conf/rewrite.mapªº¤º®e¦p¤U:  

      sg http://a.b.c.d/  
      sh http://e.f.g.h/  

      ª`¡G ·í¥Î¤á½Ð¨Dhttp://www.domain.com/sg/anypath®É³Q­«¼g¬°
      http://a.b.c.d/anypath .  
      ·í»Ý­n½Õ¸Õ®É½Ð¥Îrewritelog and rewriteloglevel 9Áp¦X,9¬°³Ì¤j§Y±o¨ì³Ì¦hªº½Õ¸Õ
      «H®§  
      ³Ì¤p¬°1¡A³Ì¤pªº½Õ¸Õ«H®§¡AÀq»{¬°0¡A¨S¦³½Õ¸Õ«H®§¡C  
      sitemapªº»yªk¬O${sitemap: LookupKey | Defaultvalue} ,¦³¨Ç®Ñ¤W§â$¼g¦¨¤F%¬O¿ù
      »~ªº¡C  
(http://www.fanqiang.com)     ¶i¤J¡iUNIX½×¾Â¡j  

--------------------------------------------------------------------------------

¬ÛÃö¤å³¹  



  


¡¹  ¼Ô±j¨î§@ Åwªï¤À¨É  ¡¹
                     




Åwªï¥úÁ{ EcStart PHP §Þ³N°Q½×½×¾Â (http://bbs.ecstart.com/) Powered by Discuz! 7.2