Ticket #436 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

getBaseUrl.py doesn't work as expected behind Apache virtual hosts

Reported by: madarche Assigned to: edegoute
Priority: P3 Milestone: unspecified
Component: CPSDefault Version: unspecified
Severity: major Keywords:
Cc:

Description (Last modified by atchertchian)

getBaseUrl.py doesn't work as expected behind Apache virtual hosts.

This bug appeared with the lattest commits on getBaseUrl.py.

Step to reproduce: * create a CPS site on a Zope instance, with "cps" as its id * visit a CPS site which is behind a virtual host, for example http://mysite.com/ * follow any link on the web site and you will discover that every link is prefixed with "cps", that is the id of the CPS site

Change History

11/26/04 15:10:48 changed by edegoute

  • status changed from new to assigned.

I need more rules to understand the whole bug. Here my generic rule: RewriteRule? /(.*) \ http://localhost:5080/VirtualHostBase/http/%{HTTP_HOST}:80/cps/VirtualHostRoot/somewhere/$1 [L,P]

It transforms domain.com/somewhere/ in localhost:5080/cps/.

11/26/04 15:13:47 changed by edegoute

  • cc set to jmo@ita.chalmers.se.

11/26/04 15:16:44 changed by madarche

Here is what I use:

ServerName? mysite.com RewriteEngine? on

RewriteCond? %{HTTP:Authorization} (.*) RewriteRule? /(.*) http://localhost:5080/VirtualHostBase/http/%{HTTP_HOST}:80/cps/VirtualHostRoot/$1 [L,P]

The only difference seems to be the presence of "somewhere" at the end of the rewrite rule.

11/26/04 15:20:04 changed by madarche

From now on, we will include the Apache httpd rewriting rule to be used with CPS with each CPS release.

11/27/04 16:15:12 changed by uli@mediamorphose.org

To examine also harder to find problems with virtual hosting, I set up the following hierarchy of folders/cps instances in zope:

root of zope

! +--cps1 ! ! +--folder--+

! +--cps2 ! +--index_html ! +--subfolder--+

! +--cps3

To check it, I tried to reach each 'reachable' cps instance defined by any of the rules below

The following 12 rewriting rules apply to the above pattern:

# case 1:

ServerName? zope1.pu.smp.net RewriteEngine? On RewriteRule? /(.*) \

http://127.0.0.1:8280/VirtualHostBase/http/zope1.pu.smp.net:80/VirtualHostRoot/$1

[L,P] ProxyVia? on

# case 2:

ServerName? cps1.pu.smp.net RewriteEngine? On RewriteRule? /(.*) \

http://127.0.0.1:8280/VirtualHostBase/http/cps1.pu.smp.net:80/cps1/VirtualHostRoot/$1

[L,P]

ProxyVia? on

# case 3:

ServerName? zope2.pu.smp.net RewriteEngine? On RewriteRule? /(.*)

http://127.0.0.1:8280/VirtualHostBase/http/zope2.pu.smp.net:80/folder/VirtualHostRoot/$1 [L,P]

ProxyVia? on

# case 4:

ServerName? cps2.pu.smp.net RewriteEngine? On RewriteRule? /(.*)

http://127.0.0.1:8280/VirtualHostBase/http/cps2.pu.smp.net:80/folder/cps2/VirtualHostRoot/$1 [L,P]

ProxyVia? on

# Inside-out hosting with single subdirectory... # case 5:

RewriteRule? /var/www/sub1/(.*) http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/VirtualHostRoot/_vh_sub1/$1 [L,P]

# case 6:

RewriteRule? /var/www/sub2/(.*) http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/cps1/VirtualHostRoot/_vh_sub2/$1 [L,P]

# case 7:

RewriteRule? /var/www/sub3/(.*) http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/folder/VirtualHostRoot/_vh_sub3/$1 [L,P]

# case 8:

RewriteRule? /var/www/sub4/(.*) http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/folder/cps2/VirtualHostRoot/_vh_sub4/$1 [L,P]

# Inside-out hosting with multiple subdirectories... # case 9:

RewriteRule? /var/www/sub5/sub1/(.*) http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/VirtualHostRoot/_vh_sub5/_vh_sub1/$1 [L,P]

# case a: RewriteRule? /var/www/sub5/sub2/(.*)

http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/cps1/VirtualHostRoot/_vh_sub5/_vh_sub2/$1 [L,P]

# case b: RewriteRule? /var/www/sub5/sub3/(.*)

http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/folder/VirtualHostRoot/_vh_sub5/_vh_sub3/$1 [L,P]

# case c: RewriteRule? /var/www/sub5/sub4/(.*)

http://127.0.0.1:8280/VirtualHostBase/http/pu.smp.net:80/folder/cps2/VirtualHostRoot/_vh_sub5/_vh_sub4/$1 [L,P]

Uli Fouquet

11/27/04 17:52:33 changed by jmorliaguet

_vh_sub5/_vh_sub2/$1 does not make much sense

why not write:

_vh_sub5/sub2/$1 ?

the doc says "VirtualHostRoot?, followed by one or *more* path elements that start with '_vh_'":

If you insert VirtualHostRoot?, followed by one or more path elements that start with '_vh_', then these elements will be ignored during traversal and then added (without the '_vh_') to the start of generated URLs. For instance, a request for "/a/VirtualHostRoot/_vh_z/" will traverse "a" and then generate URLs that start with /z.

In our example, you would have the main server send requests for http://www.mycause.org/dynamic_stuff/anything to Zope, rewritten as /VirtualHostRoot/_vh_dynamic_stuff/anything.

_

it should be enough to have:

if path_info.startswith('/VirtualHostBase/'):

# apache detection

# Inside-out hosting (VHM _vh_) if path_info.find('_vh_') > 0:

base = path_info.split('_vh_')[1] return '/' + base

else:

return '/'

and remember to set the trailing '/' in the rewrite rule.

11/28/04 15:20:00 changed by uli@mediamorphose.org

There is a difference between, let's say

_vh_sub5/cps/$1

and

_vh_sub5/_vh_cps/$1

The first expression assumes 'cps' is an existant zope object while the second one assumes it to be a virtual apache directory.

First one should return the object $1 located in a folderish zope object called cps, while the second one will return the zope object $1.

This is obvious when you watch the "VIRTUAL_URL_PARTS" variable after using both of the rules:

First one will result in something like:

('http://localhost', 'sub5', 'cps/$1')

while second one will give:

('http://localhost', 'sub5/cps', '$1' )

The docs of course can be misunderstood:

"followed by one or more path elements that start

with '_vh_'"

means

"followed by one or more path elements that start

with '_vh_' *each*"

You must have a chance to mark a difference between (existant) subdirectories in zope and (virtual) subdirectories in apache.

Therefore looking for the first occurence of '_vh_' might not be enough. There may be more of them and that with good reason.

11/28/04 15:35:25 changed by jmorliaguet

OK on the principle, but what difference is there between:

('http://localhost', 'sub5', 'cps/$1')

and:

('http://localhost', 'sub5/cps', '$1' )

when you apply '/'.join() to them which I am sure VHM does a few lines later.

what are the use cases where the distinction is important because, independently of the internal computations used, the idea is to translate a URL into another URL?

11/28/04 16:34:10 changed by uli@mediamorphose.org

I see your point.

I think, in first case the BaseUrl? should be '/cps/' while in second case it should be '/'.

This makes a difference for scripts building links (like getBreadCrumbs()).

11/29/04 10:22:12 changed by madarche

  • severity changed from blocker to major.

This bug is not blocking anymore since Encolpe has done a rollback on both HEAD and CPS-3_2-branch branches.

12/14/04 11:27:49 changed by edegoute

  • priority changed from P1 to P3.

07/26/05 01:18:04 changed by atchertchian

  • status changed from assigned to closed.
  • resolution set to fixed.
  • description changed.

Fixed in [25046]. Some issues still need to be explored, see #847