作者 主題: [Apache] mod_rewrite Virtual Host 方法  (閱讀 2513 次)

0 會員 與 1 訪客 正在閱讀本文。

appleboy

  • 活潑的大學生
  • ***
  • 文章數: 224
    • 檢視個人資料
    • 小惡魔筆記
[Apache] mod_rewrite Virtual Host 方法
« 於: 2008-03-03 17:15 »
剛剛看到一篇酷學園精華區文章

http://phorum.study-area.org/index.php/topic,17120.0.html

這篇裡面提到

引用
以下有部份取自原來我貼在 VBird 的文章
Apache 的 VH 其實設法相當多種,
相信大多數都是這種設法
<VirtualHost 1.2.3.80:80>
ServerAdmin admin@xxx.com.tw
DocumentRoot /home/httpd/html/enum
ServerName VH1.xxx.com.tw
ErrorLog logs/VH1-error.log
CustomLog logs/VH2-access_log common
</VirtualHost>
因為書本上教的,但是你改了這些值, httpd 要重新啟動...
高明點用 rewrite modules: (要有 RE 的基礎)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2

這樣只要新增 /home 目錄下的目錄就是新增 VirtualHost 了,且 httpd 不需重開
(有很多不同設法, http://httpd.apache.org/docs/misc/rewriteguide.html)

這一段,我拿去實做一下我的機器,發現我改成以下

代碼: [選擇]
RewriteEngine on
RewriteBase   /
RewriteCond   %{HTTP_HOST}                 ^test\.wu-boy\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^test\.wu-boy\.com(.*) /usr/local/www/apache22/data/test$1

我發現不會work,我把 loglevel 打開,發現他會跑無限循環

代碼: [選擇]
- - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (3) [perdir /usr/local/www/  apache22/data/] applying pattern '^(.+)' to uri 'index.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (2) [perdir /usr/local/www/  apache22/data/] rewrite 'index.php' -> 'test.wu-boy.comindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (3) [perdir /usr/local/www/  apache22/data/] add per-dir prefix: test.wu-boy.comindex.php -> /usr/local/www/apache22/data/test.wu-boy.comindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (3) [perdir /usr/local/www/  apache22/data/] strip per-dir prefix: /usr/local/www/apache22/data/test.wu-boy.comindex.php -> test.wu-boy.comindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (3) [perdir /usr/local/www/  apache22/data/] applying pattern '^test\.wu-boy\.com(.*)' to uri 'test.wu-boy.comindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (2) [perdir /usr/local/www/  apache22/data/] rewrite 'test.wu-boy.comindex.php' -> '/usr/local/www/apache22/data/testindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (2) [perdir /usr/local/www/  apache22/data/] trying to replace prefix /usr/local/www/apache22/data/ with /
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85f8050/subreq] (1) [perdir /usr/local/www/  apache22/data/] internal redirect with /testindex.php [INTERNAL REDIRECT]
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (3) [perdir /usr/local/www/ apache22/data/] strip per-dir prefix: /usr/local/www/apache22/data/index.php -> index.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (3) [perdir /usr/local/www/ apache22/data/] applying pattern '^(.+)' to uri 'index.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (2) [perdir /usr/local/www/ apache22/data/] rewrite 'index.php' -> 'test.wu-boy.comindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (3) [perdir /usr/local/www/ apache22/data/] add per-dir prefix: test.wu-boy.comindex.php -> /usr/local/www/apache22/data/test.wu-boy.comindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (3) [perdir /usr/local/www/ apache22/data/] strip per-dir prefix: /usr/local/www/apache22/data/test.wu-boy.comindex.php -> test.wu-boy.comindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (3) [perdir /usr/local/www/ apache22/data/] applying pattern '^test\.wu-boy\.com(.*)' to uri 'test.wu-boy.comindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (2) [perdir /usr/local/www/ apache22/data/] rewrite 'test.wu-boy.comindex.php' -> '/usr/local/www/apache22/data/testindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (2) [perdir /usr/local/www/ apache22/data/] trying to replace prefix /usr/local/www/apache22/data/ with /
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#860c050/initial] (1) [perdir /usr/local/www/ apache22/data/] internal redirect with /testindex.php [INTERNAL REDIRECT]
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85efb88/initial/redir#1] (3) [perdir /usr/   local/www/apache22/data/] strip per-dir prefix: /usr/local/www/apache22/data/testindex.php -> testindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85efb88/initial/redir#1] (3) [perdir /usr/   local/www/apache22/data/] applying pattern '^(.+)' to uri 'testindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85efb88/initial/redir#1] (2) [perdir /usr/   local/www/apache22/data/] rewrite 'testindex.php' -> 'test.wu-boy.comtestindex.php'
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85efb88/initial/redir#1] (3) [perdir /usr/   local/www/apache22/data/] add per-dir prefix: test.wu-boy.comtestindex.php -> /usr/local/www/apache22/data/test.wu-boy.          comtestindex.php
 - - [03/Mar/2008:17:03:54 +0800] [test.wu-boy.com/sid#814f870][rid#85efb88/initial/redir#1] (3) [perdir /usr/   local/www/apache22/data/] strip per-dir prefix: /usr/local/www/apache22/data/test.wu-boy.comtestindex.php -> test.wu-boy.        comtestindex.php

我不知道哪裡有寫錯了,有人有實做過嗎?
我覺得是
代碼: [選擇]
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]這一行有問題,大家可以幫忙看一下嗎

打開 logLevel

代碼: [選擇]
RewriteEngine on
RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 3

謝謝大家

歡迎來到 CodeIgniter 繁體中文討論區
My Blog:小惡魔 - 電腦技術 - 生活日記 - 美食介紹 - AppleBOY