Simple Joomla! SEF fix v2
Beware this content is over 10 years old and considered stale. It may no longer be accurate and/or reflect the understanding of the author but remains here for reference only. Please keep this in mind as you use this content.
A few days ago I made a post relating to an issue I came across with Joomla! during a move from running it in basic SEF mode, which utilises the aliases given when creating categories and articles in the Joomla administration/back-end, to the full/advanced SEF mode which utilises both the aliases and Apache’s
mod_rewrite to remove the index.php from the URL. Actual implementation requires a minor modification of the
.htaccess within the root Jooma directory, which I hope to cover in a subsequent post.
The script we started off with was a simple one that tried to determine the URL that the user had used or clicked on in order to access a particular resource on the website. When the resource is not found Joomla! automatically displays a standard 404 page that says something similar, that it was not found. In order to save some users from a vertible dead-end and subsequently lost traffic, I tried to hack together a few lines of PHP to save that stranded viewer and link them through to the originally linked content.
The idea was simply, that the original links that were already being cached and were now out of date, contained a reference to the index.php which provided templating information for the dynamically generating content. In comparison, the fully SEF URLs removed the index.php from the URL entirely, the result being that old URLs would no longer be able to retrieve the original content. Therefore, I simply aimed to retrieve the destination URL, remove the index.php from it and reconstruct a new URL for the visitor to click through to information they were after.
The culmination of some tinkering, leaves me with the following that works quite well so far. A break down should follow.
For now, a note on a few of the things I have added.
- Should the destination link not be a SEF related issue but simply some content has been removed or deleted entirely, a search engine is displayed to allow users to attempt a site-wide search.
I can see this being by no means fool-proof, so I would welcome other ideas or alternatives to solvinging this particular problem.