0 users online. Create an account or sign in to join them.Users

Search

A new extension, “URL Router” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

This is my first extension so I apologise in advance for any bugs or problems!!

I will try to post some examples soon, but I suspect the forum will mangle the slashes and whatnot in the regex rules.

One other thing worth mentioning - this uses the new 2.07 duplicator JS so it will not work pre-2.07 (as I understand it), but I believe that the core will work fine so I may add some conditional code to check for pre 2.07, and if so then just skip the interface which would still allow the developer to manually enter the URL routes into the DB if they wanted to.

No doubt I will get some feedback from people hacking about with it!!

Simple example (forum mangled this a bit): -

http://www.pastie.org/781730

Sweet extension. Good work!

Sweet extension. Good work!

Thanks Allen!

Has anyone managed to have a go with this yet? I’d love to get some feedback, preferably positive but if there are bugs then it’d be good to know!!

@robphilip - Can I use this to route a url like so?

  • from: http://domain.com/page/about-us
  • to: http://domain.com/about-us

If so, how would I got about doing that?

I tried this (from your example on pastie - listed above)…

http://www.pastie.org/943088

but I didn’t get it to work. (FYI: I’m using 2.0.8RC1)

Any thoughts?

NEVERMIND. I think I found what I was looking for with in the extension, Root Page Params by creativedutchmen.

It would be great if the behaviour of the routing were more configurable. At present, the extension appears to proxy the “to” URL, making it look as though it were the “from” URL. In most cases, you shouldn’t do this - it would be fantastic to be able to specify an HTTP 301 redirect to the “to” URL.

@bzerangue, Hope my extension helped!

This is a fantastic idea! Really useful to me as I’m moving an existing site however…

Invalid argument supplied for foreach()
/Users/designermonkey/Sites/portfolio/extensions/router/extension.driver.php line 60

55        }
56
57      public function save($context) {
58          $routes = array();
59          $route = array();
60          foreach($context['settings']['router']['routes'] as $item) {
61              if(isset($item['from'])) {
62                  $route['from'] = $item['from'];
63              } else if(isset($item['to'])) {
64                  $route['to'] = $item['to'];

I haven’t added any rewrites yet, and this comes up every time I try and save the preferences page.

Sorry dude!

Ok, so I fixed it by changing the following

        public function save($context) {
        $routes = array();
        $route = array();
            foreach($context['settings']['router']['routes'] as $item) {
                if(isset($item['from'])) {
                    $route['from'] = $item['from'];
                } else if(isset($item['to'])) {
                    $route['to'] = $item['to'];
                    $routes[] = $route;
                    $route = array();
                }
            }

            $this->_Parent->Database->query("DELETE FROM sym_router");
            $this->_Parent->Database->insert($routes, "sym_router");
            unset($context['settings']['router']['routes']);
    }

to the following

        public function save($context) {
        $routes = array();
        $route = array();
        if(!is_null($context['settings']['router']['routes'])){
            foreach($context['settings']['router']['routes'] as $item) {
                if(isset($item['from'])) {
                    $route['from'] = $item['from'];
                } else if(isset($item['to'])) {
                    $route['to'] = $item['to'];
                    $routes[] = $route;
                    $route = array();
                }
            }

            $this->_Parent->Database->query("DELETE FROM sym_router");
            $this->_Parent->Database->insert($routes, "sym_router");
            unset($context['settings']['router']['routes']);
        }
    }

In most cases, you shouldn’t do this - it would be fantastic to be able to specify an HTTP 301 redirect to the “to” URL.

The original intention wasn’t really for redirects as much as allowing for beautifying of URLs and one-off vanity URLs that might be going into email shots for example. If you have complex sub-pages or pages with numerous parameters, it can get ugly, so this was intended to allow the developer to keep the URLs clean.

I concede that it isn’t very flexible at present, but it serves the purpose I originally intended for it. Obviously if this can be forked and turned into something much better, that’s great.

I actually had to do a very quick 301 redirect extension for a work project recently, and used this code as the basis. It’s not complicated, I just changed the URL rewriting to send the relevant 301 redirect headers instead, but what I didn’t do was make it smart enough to have either functionality.

Thanks to everyone who has taken interest in this, it was only really meant as a learning exercise for myself, so I’m pleased it’s getting real-world use.

@bzerangue - I think you probably want this http://www.pastie.org/944967

You had an extra backslashed slash after the first slash (the start of the regex expression), so I think it was looking for a double backslash after the domain, which wouldn’t make sense.

Hi Rob, I noticed another issue. Sorry…

The uninstall function’s SQL DROP Statement is wrapped in ’ not ` and fails.

Cheers @designermonkey, just committed quick fix on github to the drop table issue. Hopefully that’ll sort it now table name is correctly wrapped in backticks.

I’ve sent you a pull request in wich I’ve fixed a small typo (wrong table prefix) and added the possibility to redirect to the new destination instead of showing the new content (including a checkbox to enable this feature).

Cheers Phoque, I’ve pulled those fixes. Appreciate you keeping this thing ticking over, I haven’t had the time lately.

This is awesome! I have been using this today to create properly hierarchical URLs such as:

/clients/
/clients/:client
/clients/:client/projects
/clients/:client/projects/:project
/clients/:client/projects/:project/wiki
/clients/:client/projects/:project/wiki/:page

Provided you’re comfortable with basic regular expressions, this is easy. Thanks!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details