我正在本地项目中进行一些测试(使用 vHosts)。我设法创建了一个 RewriteRule 以重定向something.kensaku.com
到www.kensakuapp.com/something
,但我想重定向something.kensaku.com/myapp
到www.kensakuapp.com/something/myapp
.
我的重写规则是这样的:
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 的情况下做到这一点,我会很高兴知道它——但如果可能的话,我想继续使用 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 admin@kensaku.com
DocumentRoot /opt/lampp/htdocs/kensaku
ServerName kensaku.com
ServerAlias *.kensaku.com
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@kensaku.com
DocumentRoot /opt/lampp/htdocs/kensakuapp
ServerName kensakuapp.com
ServerAlias *.kensakuapp.com
</VirtualHost>