我正在本地項目中使用vHosts進行一些測試。我已經設法創建一個重寫規則來重定向something.kensaku.com
到www.kensakuapp.com/something
,但我想重定向something.kensaku.com/myapp
到www.kensakuapp.com/something/myapp
。嘗試使用RewriteRule匹配子域和路徑,只獲取子域
我重寫規則是這樣的一個:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.kensaku.com
RewriteRule ^(^.*) goto.php?username=%1&path=$1
我一直在嘗試了好幾個小時,我仍然不能設法得到/myapp
部分。如果我去something.kensaku.com/myapp
,$1
將匹配goto.php
,但不應該匹配/myapp
?
這裏的goto.php
腳本我使用重定向的內容:
<?php
$user = $_GET['username'];
header("Location: http://www.kensakuapp.com/$user/".$_GET['path']);
?>
如果有其他的方法可以做到這一點,而不使用PHP,我會感激知道 - 但如果可能的話我d喜歡繼續使用PHP方法,因爲將來也許我會爲它添加跟蹤或日誌記錄功能。
如果我錯過了任何問題,請告訴我!
編輯:日誌中的rewritemod,跟蹤3:
[Wed Mar 20 19:26:28.624291 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7d120/initial] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/
[Wed Mar 20 19:26:28.624352 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.html
[Wed Mar 20 19:26:28.624402 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.html.var
[Wed Mar 20 19:26:28.624434 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.php
[Wed Mar 20 19:26:28.630172 2013] [rewrite:trace3] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7f2f0/initial] [perdir /opt/lampp/htdocs/kensaku/] strip per-dir prefix: /opt/lampp/htdocs/kensaku/ ->
[Wed Mar 20 19:26:28.630202 2013] [rewrite:trace3] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7f2f0/initial] [perdir /opt/lampp/htdocs/kensaku/] applying pattern '^.+$' to uri ''
[Wed Mar 20 19:26:28.630216 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7f2f0/initial] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/
[Wed Mar 20 19:26:28.630277 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.html
[Wed Mar 20 19:26:28.630327 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.html.var
[Wed Mar 20 19:26:28.630360 2013] [rewrite:trace1] [pid 24190] mod_rewrite.c(467): [client 127.0.0.1:52996] 127.0.0.1 - - [www.kensaku.com/sid#982bb28][rid#9a7b118/subreq] [perdir /opt/lampp/htdocs/kensaku/] pass through /opt/lampp/htdocs/kensaku/index.php
編輯2:這裏是虛擬主機:
# Kensaku Domains
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /opt/lampp/htdocs/kensaku
ServerName kensaku.com
ServerAlias *.kensaku.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /opt/lampp/htdocs/kensakuapp
ServerName kensakuapp.com
ServerAlias *.kensakuapp.com
</VirtualHost>
使用「RewriteLog」和「RewriteLogLevel」啓用日誌記錄併發布相關日誌。 – larsks 2013-03-18 19:48:57
日誌已經被採取使用奧拉夫的規則,試圖去'www.kensaku.com'。 – 2013-03-20 18:30:01