Apache, VirtualHostMonster and complex rewriterule
Hi, I'm trying to make some complex RewriteRule to map : http://nick1.mydomain.com/pathx -> Zope /nick1/pathx http://nick2.mydomain.com/pathy -> Zope: /nick2/pathy ... I thought I had some skills in that matter but... <VirtualHost *> ServerName *.mydomain.com RewriteEngine on RewriteRule ^(.*)\.mydomain\.com/(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/$1/VirtualHostRoo t/$2 [P,L] </VirtualHost> ... doesn't work I inspected the Z2.log and found that the second group matches when the first does'nt : When getting http://foo.mydomain.com/bar , the path in Z2.log is : /VirtualHostBase/http/foo.mydomain.com:80//VirtualHostRoot/bar ...when I expected... /VirtualHostBase/http/foo.mydomain.com:80/foo/VirtualHostRoot/bar Can somebody help ? What's wrong in the RewriteRule pattern ? Many thanks in advance. --Gilles
Gilles Lenfant wrote at 2003-1-24 20:47 +0100:
I'm trying to make some complex RewriteRule to map :
http://nick1.mydomain.com/pathx -> Zope /nick1/pathx
http://nick2.mydomain.com/pathy -> Zope: /nick2/pathy
...
I thought I had some skills in that matter but...
<VirtualHost *> ServerName *.mydomain.com RewriteEngine on RewriteRule ^(.*)\.mydomain\.com/(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/$1/VirtualHostRoo t/$2 [P,L] </VirtualHost>
... doesn't work
I inspected the Z2.log and found that the second group matches when the first does'nt : When getting http://foo.mydomain.com/bar , the path in Z2.log is :
/VirtualHostBase/http/foo.mydomain.com:80//VirtualHostRoot/bar
...when I expected...
/VirtualHostBase/http/foo.mydomain.com:80/foo/VirtualHostRoot/bar Add rewrite logging and lock at the log file.
Dieter
----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Sunday, January 26, 2003 7:39 PM Subject: Re: [Zope] Apache, VirtualHostMonster and complex rewriterule
Gilles Lenfant wrote at 2003-1-24 20:47 +0100:
I'm trying to make some complex RewriteRule to map :
http://nick1.mydomain.com/pathx -> Zope /nick1/pathx
http://nick2.mydomain.com/pathy -> Zope: /nick2/pathy
...
I thought I had some skills in that matter but...
<VirtualHost *> ServerName *.mydomain.com RewriteEngine on RewriteRule ^(.*)\.mydomain\.com/(.*)
http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/$1/VirtualHostRoo
t/$2 [P,L] </VirtualHost>
... doesn't work
I inspected the Z2.log and found that the second group matches when the first does'nt : When getting http://foo.mydomain.com/bar , the path in Z2.log is :
/VirtualHostBase/http/foo.mydomain.com:80//VirtualHostRoot/bar
...when I expected...
/VirtualHostBase/http/foo.mydomain.com:80/foo/VirtualHostRoot/bar Add rewrite logging and lock at the log file.
Dieter
Thanks Dieter, With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically. --Gilles
Gilles Lenfant wrote:
With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically.
I am fairly certain that if you reverse the order of the AddModule lines for mod_proxy and mod_rewrite in your Apache config, you can rewrite based on full URLs. *Warning*: this will probably require you to edit *every* RewriteRule in your Apache config. Cheers, Evan @ 4-am
----- Original Message ----- From: "Evan Simpson" <evan@4-am.com> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Monday, January 27, 2003 5:52 PM Subject: [Zope] Re: Apache, VirtualHostMonster and complex rewriterule
Gilles Lenfant wrote:
With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically.
I am fairly certain that if you reverse the order of the AddModule lines for mod_proxy and mod_rewrite in your Apache config, you can rewrite based on full URLs.
*Warning*: this will probably require you to edit *every* RewriteRule in your Apache config.
Cheers,
Evan @ 4-am
Evan, Reversing the order of AddModule lines didn't change anything. The RewiteRule reg expr is always compared with the path. I spent hours reading again and again the mod_rewrite doc and didn't find any solution. Cheers, --Gilles
On Monday, January 27, 2003, at 10:51 AM, Gilles Lenfant wrote:
With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically.
Look into RewriteCond - it supports conditional based upon the host. In you case, something like: RewriteCond {HTTP_HOST} ^nick1.* RewriteRule ^(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/nick1/ VirtualHostRoot/$1 [P,L] RewriteCond {HTTP_HOST} ^nick2.* RewriteRule ^(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/nick2/ VirtualHostRoot/$1 [P,L] This way, all your nick1.mydomain.com requests get rewritten one way, and your nick2.mydomain.com requests get rewritten a different way. ___/ / __/ / ____/ Ed Leafe http://leafe.com/ http://opentech.leafe.com
Ed Leafe wrote:
Look into RewriteCond - it supports conditional based upon the host. In you case, something like:
Ah, yes. Better yet, some variant of the following may work: RewriteCond %{HTTP_HOST} ^(.*)\.myhost\.com RewriteRule ^(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/%1/VirtualHostRoot/$1 [P,L] Cheers, Evan @ 4-am
----- Original Message ----- From: "Evan Simpson" <evan@4-am.com> To: <zope@zope.org> Cc: "Ed Leafe" <ed@leafe.com>; "Gilles Lenfant" <gilles@pilotsystems.net> Sent: Monday, January 27, 2003 7:24 PM Subject: [Zope] Re: Apache, VirtualHostMonster and complex rewriterule
Ed Leafe wrote:
Look into RewriteCond - it supports conditional based upon the host. In you case, something like:
Ah, yes. Better yet, some variant of the following may work:
RewriteCond %{HTTP_HOST} ^(.*)\.myhost\.com RewriteRule ^(.*)
http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/%1/VirtualHostRoo t/$1
[P,L]
Cheers,
Bingo ! Exactly what I needed ! Many thanks Evan and Dieter for the enlightenments. --Gilles
Using %{HTTP_HOST} is not recommended as it will contain the port if present in the URL. %{SERVER_NAME} works perfectly for me, however. Stefan --On Montag, 27. Jänner 2003 12:24 -0600 Evan Simpson <evan@4-am.com> wrote:
Ed Leafe wrote:
Look into RewriteCond - it supports conditional based upon the host. In you case, something like:
Ah, yes. Better yet, some variant of the following may work:
RewriteCond %{HTTP_HOST} ^(.*)\.myhost\.com RewriteRule ^(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/%1/VirtualHost Root/$1 [P,L]
Cheers,
Evan @ 4-am
-- Those who write software only for pay should go hurt some other field. /Erik Naggum/
Gilles Lenfant wrote at 2003-1-27 16:51 +0100:
With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically. You may try "RewriteCond" on the "HTTP_HOST" variable.
Dieter
----- Original Message ----- From: "Dieter Maurer" <dieter@handshake.de> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Monday, January 27, 2003 8:56 PM Subject: Re: [Zope] Apache, VirtualHostMonster and complex rewriterule
Gilles Lenfant wrote at 2003-1-27 16:51 +0100:
With the rewritelog, I can see that the regular expression searches matches in the *path* and not to the *URL* (as stated in mod_rewrite doc). Such it wont pass anything to the expected $1 and $2 :( I got to find out another way to virtualhost dynamically. You may try "RewriteCond" on the "HTTP_HOST" variable.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Many thanks again Dieter. This is the solution ! --Gilles
participants (5)
-
Dieter Maurer -
Ed Leafe -
Evan Simpson -
Gilles Lenfant -
Stefan H. Holek