1

My custom Joomla component hosts event pages for a range of clients under distinct sub-domains, many with their own separate page templates, tailored to match the appearance of their own websites for continuity. This often includes the client's own favicon for use in browser tabs.

It is common for browsers to request a favicon.ico file from the root of the site, even if this is not expressly described in the <head> section of the page. Since I have different favicons for different pages, I store these with the page templates rather than in the root directory of my site.

In Joomla 3, I used the following Apache RewriteRule to pass handling of the favicon requests off to a controller in my component:

RewriteRule ^/favicon.ico$ /index.php?option=com_mycomponent&task=util.favicon [L]

However, the Joomla 4 SEF router logic no longer plays well here, since it throws an error if there are still unresolved elements left in the request uri after all of the routing steps have completed. That is, after the SEF routing steps have finished, the request uri still contains 'favicon.ico' since it did not match anything in the system and so the router throws an error, even though Apache has populated the $_SERVER['QUERY_STRING'] with the query parameters given above.

I have tried creating a hidden menu item to handle this, instead of a RewriteRule. However, as soon as I try to save it with the alias 'favicon.ico', this predictably gets revised to 'favicon-ico', so won't match the incoming requests.

What would be the best way to do this routing in Joomla 4+?

It is worth noting that there is no guaranteed mapping between a subdomain and a page template location, so I do need to have some PHP code in my component determine the correct file to serve up, and cannot simply revise the RewriteRule above to map directly to the correct file location ie. by-passing Joomla altogether).

3
  • Any reason you're not including the favicon in the template or using a plugin? Rewrites like this weren't really supported. They just happened to work until J4. Anyways, this PR and associated issue may be relevant github.com/joomla/joomla-cms/pull/42150.
    – Sharky
    Commented Jun 10 at 7:53
  • @Sharky I have a single template that has many sub-folders for the different clients - this is much simpler for me to manage than registering a new template in Joomla for each client - the client record has the name of the folder (if not using the default template) to pull the template from. Hence, the one Joomla template will have many favicons in different subfolders.
    – John Rix
    Commented Jun 10 at 23:15
  • Regarding the PR you mentioned there, I could certainly use that change to solve my problem. I would just need to change my rewritten URL to 'index.php/favicon?option=com_mycomponent&task=util.favicon and then add a menu item with alias 'favicon' that would then be utilised. What is the status of that change though? It was closed, but why? It is not part of the current codebase anyway.
    – John Rix
    Commented Jun 10 at 23:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.