我试图编写一套mod_rewrite规则,允许我的用户利用单个文件夹在不同的项目上进行开发,而不必与添加虚拟主机为每一个单一的项目。Apache mod_rewrite一个子文件夹到子文件夹(通过内部重定向)
我的想法是为每个需要这种能力的用户(只有3-4个)设置一个“Global VHost”,这个虚拟主机就像是:.my-domain.com。从那里,我想促进我的用户编写代码,就好像它在一个域中,而不是在一个子文件夹中。例如,如果bob正在开发一个名为'gnome'的项目,那么我希望URL链接(以及我们内部网络上的其他人)加载到此项目中:http://gnome.bob.my-domain.com。但是,我希望Apache做的事情是认识到“gnome”是一个“项目”,因此将内部请求映射到bob.my-domain.com/gnome/。
我已经得到了我认为能够工作的东西,而且它非常简单,但是它不起作用!该请求只是进入无限循环,并将子域的前缀保留在重写的请求URI上。
国防部重写代码,我是:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.bob\.my-domain\.com
RewriteCond %{REQUEST_URI} !^/%1.*
RewriteRule ^(.*)$ /%1/$1 [L]
我张望了一下这个GOOGLE了,但我还没有找到任何工作,真正的解决方案。有没有人试过 - 或者,有没有人有更好的主意?一个不涉及为每个项目制作虚拟主机(我有设计师......我想每个人都会同意设计师不应该制作虚拟主机..)
谢谢!
下面是从rewrite_log一个片段:
[rid#838dc88/initial] (3) [perdir /home/bob/http/] strip per-dir prefix: /home/bob/http/index.html -> index.html
[rid#838dc88/initial] (3) [perdir /home/bob/http/] applying pattern '^(.*)$' to uri 'index.html'
[rid#838dc88/initial] (4) [perdir /home/bob/http/] RewriteCond: input='gnome.bob.my-domain.com' pattern='^([^.]+)\.bob\.my-domain\.com' => matched
[rid#838dc88/initial] (4) [perdir /home/bob/http/] RewriteCond: input='/index.html' pattern='!^/%1.*' => matched
[rid#838dc88/initial] (2) [perdir /home/bob/http/] rewrite 'index.html' -> '/gnome/index.html'
[rid#838dc88/initial] (1) [perdir /home/bob/http/] internal redirect with /gnome/index.html [INTERNAL REDIRECT]
[rid#8392f30/initial/redir#1] (3) [perdir /home/bob/http/] strip per-dir prefix: /home/bob/http/gnome/index.html -> gnome/index.html
[rid#8392f30/initial/redir#1] (3) [perdir /home/bob/http/] applying pattern '^(.*)$' to uri 'gnome/index.html'
[rid#8392f30/initial/redir#1] (4) [perdir /home/bob/http/] RewriteCond: input='gnome.bob.my-domain.com' pattern='^([^\.]+)\.bob\.my-domain\.com' => matched
[rid#8392f30/initial/redir#1] (4) [perdir /home/bob/http/] RewriteCond: input='/gnome/index.html' pattern='!^/%1.*' => matched
[rid#8392f30/initial/redir#1] (2) [perdir /home/bob/http/] rewrite 'gnome/index.html' -> '/gnome/gnome/index.html'
[rid#8392f30/initial/redir#1] (1) [perdir /home/bob/http/] internal redirect with /gnome/gnome/index.html [INTERNAL REDIRECT]
[rid#8397970/initial/redir#2] (3) [perdir /home/bob/http/] add path info postfix: /home/bob/http/gnome/gnome -> /home/bob/http/gnome/gnome/index.html
这仅仅是一个代码段,也有少数10S或100行左右的apache的基本上重写/gnome/index.html到/侏儒/侏儒/gnome/gnome/gnome/index.html等之前的Apache达到其极限改写,放弃,并引发错误500
在重写日志中添加了一些更多信息,希望以前有人尝试过,或者对如何完成此操作有一些输入!谢谢你们(和加尔斯) – 2009-07-22 18:32:55