Ticket #121 (assigned enhancement)

Opened 8 years ago

Last modified 8 years ago

Make Page_Forward work with relative URIs

Reported by: svenfuchs@… Owned by: schst@…
Priority: low Milestone: v0.5.0
Component: Framework Version: devel
Severity: normal Keywords:
Cc:

Description (last modified by schst) (diff)

How to redirect to a relative uri?

Don't know if this is the way I'm meant to go, but I tried to integrate a Wordpress blog into a site by adding a Page_Forward to the sitemap. Something like:

Home (index.php) + Services (index.php?path=home.services) + [...] + Blog (index.php?path=home.blog -> forward to /blog/index.php)

Looking at Response_Http::forwardTo(), it's not possible to use a relative uri by doing something like

<page:forward title="Blog" uri="./blog/" relevance="100"/>

As far as I understand the design, forwardTo() would need the request as an additional parameter to be able to look at the request's base uri and prepend it to a relative forward uri.

So I tried to change the interface's protocol to:

Response_Http::forwardTo($uri, patPortal_Request $request)

But then I noticed that there's no method available in $request to determine the raw "base uri" (as I understand it), i.e. an uri like http://domain.ltd/myproject/

Instead, Request_Http::getBaseUri() returns the complete dispatcher uri like http://domain.ltd/myproject/index.php

Don't know if it's appropriate to change the Request's api. I'd find it more intuitive to have something like:

Request_HTTP::getBaseUri() {

return http://domain.ltd/myproject/

} Request_HTTP::getSelfUri() {

return http://domain.ltd/myproject/index.php

} Request_HTTP::getPathUri() {

return http://domain.ltd/myproject/index.php?__path=home

}

and in Response_HTTP::replaceUrls() replacement of tokens

PORTAL_BASE_URI PORTAL_SELF_URI PORTAL_PATH_URI

With:

Response_Http::forwardTo($uri, patPortal_Request $request) {

$this->data = $uri; $this->replaceUrls($request);

$parts = parse_url($this->data); if (!isset($partsscheme?)) {

$this->data = $request->getBaseUri() . $this->data; $parts = parse_url($this->data);

}

probably further sanitize uri ...

$this->addHeader('Location', $this->data); $this->data = null;

}

forwarding to relative urls could be done by:

<page:forward title="Blog" uri="[PORTAL_BASE_URI]/blog/" />

or alternatively by:

<page:forward title="Blog" uri="./blog/" />


For now - without screwing up any api/bc, a simple solution could be to just modify Response_Http::forwardTo() like follows:

public function forwardTo($uri) {

$parts = parse_url($uri); if (!isset($partsscheme?)) {

$uri = 'http://' . $_SERVERHTTP_HOST? .

dirname($_SERVERPHP_SELF?) . '/' . $uri;

$parts = parse_url($uri);

} build internal URIs /* switch ($partsscheme?) {

default:

break;

} */ $this->addHeader('Location', $uri); $this->data = null;

}

Change History

comment:1 Changed 8 years ago by schst@…

  • Status changed from new to assigned

comment:2 Changed 8 years ago by schst

  • Description modified (diff)
  • Milestone set to Development Release
Note: See TracTickets for help on using tickets.