Forum

Thread tagged as: Question

Omit URL segment for a "node"?

In relation with the use of various domains for the same site (which contain some part of the information already), I would like to remove a segment from the URL.

In Perch I have a simplistic multi-tree setup

+ Home En (/en)
+- Page1 En (/en/page1)
+- Page2 En (/en/page2)

+ Home Fr (/fr)
+- Page1 Fr (/fr/page1)
+- Page1 Fr (/fr/page2)

The domains are

www.englishdomain.com www.frenchdomain.com

All perfectly fine. The only issue is that I'd rather not show /de/ and /fr/ to users. So instead of www.englishdomain.com/en/page1 (which is redundant) we want the URL www.englishdomain.com/page1

This would require two steps:

a) Omit the /en and /fr when generating the perch_pages_navigation (because it will be prepended with said domain) - is that possible at all in a useful way?

b) Allow me to rewrite the route somewhere in the template before it's being passed to start.php for use in $Router->get_route (see https://forum.grabaperch.com/forum/12-09-2015-analyze-routes-in-runway, but I'm NOT pushing, just interested)

Any chance for a)? Else, we'll live with the redundant URL for the moment

Urs Bräm

Urs Bräm 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

a) you could use the replace attribute in your navigation template

b) there's nothing before start.php - the front controller matches then route then calls the template. There's nothing you can do in a template to control how the template is chosen.

a) sounds fine

b) not sure if I understand: What I meant was modifying the value that is passed to $RoutedPage = $Router->get_route($_SERVER['REQUEST_URI']);

Optionally, allow some prior modification of the URI (config.php for example is loaded there already) and passing a custom variable - instead of passing the pure $_SERVER variable.

Like an optional Hook for people who need to modify the route before it's being processed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't understand your question, I'm afraid.

Sorry... I'm suggesting the following code changes in runway's start.php

<?php
    if (PHP_VERSION_ID<50400) die('Perch Runway requires PHP 5.4 or greater.');

    define('PERCH_RUNWAY_ROUTED', true);

    include(__DIR__.'/../runtime/runtime.php');
    if (!PERCH_RUNWAY) die('Perch Runway requires a Runway license key.');

    # Routing
    $Router     = new PerchRouter;
        // my suggestion
        if(defined(CUSTOM_URI)){
           $request_uri = CUSTOM_URI;
        }
        else {
           $request_uri = $_SERVER['REQUEST_URI'];
        }
    $RoutedPage = $Router->get_route($request_uri);
        // end of my suggestion
        // would replace
        // $RoutedPage = $Router->get_route($_SERVER['REQUEST_URI']);

The reason is that as far as I know, if you don't have mod_proxy installed, you can't and shouldn't modify $_SERVER['REQUEST_URI'].

But like this, e.g. in config.php, it would be possible to transform the received URI to something else via PHP. Which seems something I'd have to do to achieve the desired result as described above.

I'm leaving it there, maybe you find it useful.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah ok, I see what you mean. I'll give it some thought.

btw, your Runway is out of date.

Runway is out of date

oh, thanks!