last day (15 days later) » 

11:46 PM
0
A: Routing in SilverStripe using regex

Dan HensbyYou can do something like this: public function index($request) { $url = $request->param('Slug'); $matches = array(); if (strpos($url, '/') === false && preg_match('/^[a-z\-]+\-i([0-9]+)/i', $url, $matches)) { return "matched " . var_export($matches, true); } return C...

 
I could write the following code which very similar to the code you suggested public function index($request) { if ($passed_regex) { return MatchedPage_Controller::create()->handleRequest($request, $this->model); } else { } } Now I can detect my pattern urls with regexp and handle it to the right controller. But the problem when the slug doesn't match the pattern, for example: example.com/admin, the slug param will be 'admin' it will not match the regexp, then a blank page will be displayed. I want some code in the else that continue handling non matching urls to their controller
 
You're intercepting too many routes if it takes over /admin
 
It's not just about admin, actually any url slug for a page that I already created from the cms, and comes directly after the site name, for example: example.com/contact-us
 
Hmm. This is generally a really bad approach. I think you'd have to customise director to really get this going. I've asked for more info on what the actual use case is here. Why you need to use this url format. Can I have it?
 
Any idea how to do that ?
 
11:46 PM
I'm waiting for the information I've asked for
 
@Dan excuse me but what information are you asking for ?
 
I'm looking to understand what you're overall objective is
why do you need to handle these URLs? is it to handle legacy URLs is it for some kind of integration with another DB?
@Kamal
 
Yes I am working for mapping old site to a new one with fresh installation of silverstriple, the client already have many urls of his site over the web and he wants to keep them as they are. As I already explained in the question the pattern of the url. The pattern url are coming directly after the site name, here is an example
example.com/some-text-slug-tx-i1654766, when I detect this url I want to detect the id and do a custom query to a remote database and show the information in a custom template SS.
 
Why not just do 301s for them? it's much more simple and can be done on Page_Controller::init()
keeping legacy URLs doesn't have much of an advantage
you could do this at .htaccess level too
 

  last day (15 days later) »