Support

Admin Tools

#26929 redirect to category

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by on Wednesday, 22 February 2017 17:17 CST

JohnB
 Not really sure if it has to do with Admin tools (.htaccess?)but I am just cannot find a clue online.

When I put rubbish behind my www.divemood.com/ it does not tricker a 404 error, but instead goes to a category list
When I put rubbish behind eg www.divemood.com/liveaboards/carina it does tricker a 404 error.

Where could this category list come from? Just cannot figure it out why this happens.

Any help appreciated1

nicholas
Akeeba Staff
Manager
Nope, nothing to do with Admin Tools. This is a side effect of the way Joomla's routing works. "Routing" is the way Joomla processes a SEF URL (one without index.php?... in it) to understand what you mean.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

JohnB
Thanks Nicholas, even though was hoping you could give me a clue on how to get this in order as I am really impressed by Akeeba and your knowledge. Understand though that it is not your job and . . . will struggle on till solution.

Seems so logical that all non existing urls should be forwarded to something like a created 404 page, but though probably everyone would want this . . . not so clear to see through this.

nicholas
Akeeba Staff
Manager
It actually makes sense. Bear with me for a minute.

A SEF URL is actually a URL which does not exist on the server. That is to say, when you go to https://www.akeebabackup.com/support there is no folder or file called support on our server. Normally the web server (Apache) would see that and return an HTTP 404 Not Found response.

However, I want this pretty and easy to remember URL to be equivalent to the ugly and difficult to remember URL https://www.akeebabackup.com/index.php?option=com_ats&Itemid=.... So, how can I convince my site to convert an invalid URL to something that is actually usable, without exposing the ugly URL to the user?

Enter SEF URLs.

Joomla's SEF URLs (and WordPress permalinks, and Drupal's URLs, and... you get the idea) are actually a two-fold magic trick. The first part of the magic trick is telling Apache to redirect invalid URLs to a PHP script. The other part of the magic trick is some PHP code which tries to make sense of the invalid URL and do something useful with it.

The first part of the magic trick is something you do in the configuration of the web server. On an Apache server the simplest way to do that is through .htaccess files. Joomla! comes with the following code in its proposed .htaccess file:
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

Read the comments (the lines beginning with #) to understand what it does. As you see, if it's something which would result in a 404 error it gets redirected to Joomla's index.php file.

The second part of the magic trick is Joomla's most powerful feature: the SEF router. It's actually a whole ecosystem of plugins. Assuming that you're using Joomla's built in SEF system, as opposed to something like sh404SEF, AceSEF and so on, the first bit of it lies in the System - SEF plugin. This plugin checks to see if any part of the SEF path (the thing after the first /) matches your menu structure. This lets Joomla determine two important things: the menu item ID (called Itemid in Joomla parlance) and the component which is meant to handle the request. If there are more SEF path parts not handled by the Joomla menu system the SEF router will look into the detected component's for a file called router.php (called the "component's SEF router") and ask it to handle the remaining parts. In the end of the day Joomla has converted the SEF URL into a set of keys and values which it can use to load a component and ask it to render a page. And that's how our /support URL ended up being a page generated by our ticket system component displayed to you.

But what happens when the System - SEF plugin cannot find a suitable menu item for the SEF URL you gave it, as it happens when you type junk in the URL? Well, no menu item is found so Joomla! thinks falls back to handling it as content (articles). But there's no content (article) category by that name either, hence the built-in com_content component throws an error about a missing category.

I hope that shed some light into the magic that goes into handling your URL and explained why you see what you see :)

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

JohnB
Whoo Nicholas, thanks for the great explanation, really thankful.

At the end unfortunately means that avoiding this wrong redirections is not easy to tackle without rewriting some router.php files. A real shortcoming of joomla in this case I would say. At then end you want people to visit sites that they want to visit exclusively and no router.php trying to figure out what they might have wanted . . . plus minus. Probably someone made some plugin for this to avoid that . . . now just to find it.

One small question: does it matter where mentioned rewriterules you mention are in .htaccess? Mine are pretty much towards the end.

nicholas
Akeeba Staff
Manager
Avoiding the redirection is impossible without breaking your site's SEF URLs. That's also true for every other PHP-based CMS out there; 404 errors are redirected to the CMS and what happens after that is very site- and CMS-dependent.

BUT! If you know how to use Joomla's core features you do not need to use any plugins or make your life harder. Check your template's directory for an error.php file. It is what is used to display all error messages on your site. If there is no such file copy it from templates/system/error.php. Now you can customise it to make it easier for the visitors to understand what is going wrong. Case in point, our custom 404 page.

One small question: does it matter where mentioned rewriterules you mention are in .htaccess? Mine are pretty much towards the end.


Yes, it does. These must be the last RewriteRule lines in the .htaccess file. Otherwise they will cause Apache to handle the request immediately, without processing any other rules. Please note that other Apache directives (e.g. AddHandler) can appear after them. It's just RewriteRule lines which shouldn't be after that block of .htaccess code.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

System Task
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!