Hi,
I’m trying to make the following.
With user friendly url’s turned on its possible for users to go to: website.com/cars/chevrolet/avalanche
No problem here.
What I want to do is to make the car brand and model dynamic, so:
website.com/cars/*brand-name*/*model-name*
Where brand-name and model-name are loocked up in the database, and the information is shown.
I could find a standard wa to do this in mod-x, so I created a snippet which is called on the 404 page.
this snippet say:
<?php
// Getting the requested URL:
$RequestURL = $_SERVER[’REQUEST_URI’];
// is it a car?
if (strpos($RequestURL, "cars/") <> 0) {
$occasionURL = str_replace("http://", "", $RequestURL);
$split_url = explode(’/’, $occasionURL);
$occasionbasis = $split_url[1];
$brand = $split_url[2];
$model = $split_url[3];
//redirect
if ($model != "") {
$occasionDocID = 27;
} else {
$occasionDocID = 26;
}
// redirect
$modx->sendForward($occasionDocID);
}
?>
This works great and very smooth in Firefox on the Mac,
But in internet explorer 6 and 7 and Firefox on Ubuntu I get the following error:
ERROR: Too many forward attempts!
The request could not be completed due to too many unsuccessful forward attempts.
This Error is generated by this function:
<?php
function sendForward($id, $responseCode= ’’) {
if ($this->forwards > 0) {
$this->forwards= $this->forwards - 1;
$this->documentIdentifier= $id;
$this->documentMethod= ’id’;
$this->documentObject= $this->getDocumentObject(’id’, $id);
if ($responseCode) {
header($responseCode);
}
$this->prepareResponse();
exit();
} else {
header(’HTTP/1.0 500 Internal Server Error’);
die(’<h1>ERROR: Too many forward attempts!</h1><p>The request could not be completed due to too many unsuccessful forward attempts.</p>’);
}
}
?>
Can someone explane to me why "$this->forwards > 0" is true in Firefox mac and false in the other browser/OS cobinations?
Thnx,
Marc
-
MODX Staff
- 10,725 Posts
You might want to think about using the OnPageNotFound event to attach a plugin, rather than running the script on your 404 page. This will intercept the request and allow you to decide how to handle the non-standard URL...