Question

let's say you have a url like this entered in modx Evo

www.zipit.com.org/reference/toamovie/

if I have a page called toamovie whose parent is called reference

but when someone enters that url I want it to do the equivalent of this

www.zipit.com.org/reference.html?myvar=toamovie

additionally, or more importantly, I'd like the result to be more like this, where 12 wouls be the id of a document

`www.zipit.com.org/reference.html?myid=12'

I'm wondering if this is at all possible with modx Evolution.I'm thinking that this should be possible to do with some htaccess magic, well the first part anyway. How could I get a value that the document? This would be quite inaccessible with htaccess, so there would need to be another part to it that could plug into the database and get that value.

Was it helpful?

Solution

It should be possible with a custom plugin called on the "OnPageNotFound" event.

<?php
$url = $_SERVER['REQUEST_URI']; //get the url        
//split the url into pieces and remove empty values
$pieces = array_filter(explode('/', $url));

//reset the array keys
$temp = array();
foreach ($pieces as $piece) {
    $temp[] = $piece;
}
$pieces = $temp;

//basic checking of the url
if (count($pieces) == 2) {
    $modx->sendRedirect('http://www.zipit.org/' . $pieces[0]  .".html?myid=" . $pieces[1]);
}
?>

remember that plugins aren't wrapped in php tags. also that this script will pass any incorrect urls to zipit.org. Some error handling is probably desireable.

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