Question

A couple of months ago, I built this lead dashboard (*) in pure PHP.

A key feature of my lead dashboard is that it's very flexible in its URL parsing. Parameters can be added to the end of the URL and the order or quantity really doesn't matter. See examples below.

I'm currently porting my dashboard to a Wordpress system and would like to maintain this same flexibility, but it's not really clear to me what would be a good strategy in Wordpress to implement this routing technique. Should I go for an .htaccess based solution? Should I add a filter? Should I add an action? And which filter or action would seem the most suitable?

Any suggestions on how to do this the right way?


Example URL 1 :

http://www.johnslegers.com/lead-dashboard/

Example URL 2 :

http://www.johnslegers.com/lead-dashboard/keyword:Stackoverflow

Example URL 3 :

http://www.johnslegers.com/lead-dashboard/keyword:Stackoverflow/language:English

Example URL 4 :

http://www.johnslegers.com/lead-dashboard/language:English,Dutch/keyword:Stackoverflow,problem

Example URL 5 :

http://www.johnslegers.com/lead-dashboard/value:3500/percentage:5,15,30,50,70/language:English,French,German/keyword:Stackoverflow,problem

Example URL 6 :

http://www.johnslegers.com/lead-dashboard/keyword:Stackoverflow,%20programming,%20code,%20Wordpress,%20problem/language:English/currency:US%20Dollars/percentage:5,10,20,50,85/cost:0.9,9,34,108/value:5400

EDIT :

(*) Google decided to impose an RMF policy that requires any dev to implement a long list of features of they want to use their Adwords API. Because my app uses only a few features of Adwords and thus doesn't comply with this policy, Google no longer allows me to access their API. This means that the tool no longer functions correctly and cannot be fixed unless Google decides to change their policy. Because the tool no longer functions correctly, I removed the link.

Was it helpful?

Solution

I ended up solving this issue myself.

To fix my problem, I just had to add the following action function to the functions.php file of my theme :

function simulationpage_init() {
    // Remember to flush the rules once manually after you added this code!
    add_rewrite_rule(
            // The regex to match the incoming URL
            'simulatie/.*',
            // The resulting internal URL
            'index.php?pagename=simulatie&data=$matches[1]',
            // This is a rather specific URL, so we add it to the top of the list
            'top');

    flush_rewrite_rules();
}

add_action('init', 'simulationpage_init');

That achieved exactly what I wanted!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top